home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / ast.h < prev    next >
C/C++ Source or Header  |  1999-10-20  |  188KB  |  6,101 lines

  1. // $Id: ast.h,v 1.18 1999/10/19 23:13:34 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10.  
  11. #ifndef ast_INCLUDED
  12. #define ast_INCLUDED
  13.  
  14. #include "config.h"
  15. #include <assert.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include "stream.h"
  19. #include "symbol.h"
  20. #include "set.h"
  21.  
  22. class Parser;
  23. class SemanticEnvironment;
  24. class StoragePool;
  25.  
  26. class VariableSymbolArray
  27. {
  28.     typedef VariableSymbol * T;
  29.  
  30.     T **base;
  31.     size_t base_size;
  32.     int top,
  33.         size;
  34.     StoragePool *pool;
  35.     unsigned short log_blksize,
  36.                    base_increment;
  37.  
  38.     inline size_t Blksize() { return (1 << log_blksize); }
  39.  
  40.     //
  41.     // Allocate another block of storage for the VariableSymbol array.
  42.     //
  43.     void AllocateMoreSpace();
  44.  
  45. public:
  46.  
  47.     //
  48.     // This function is used to reset the size of a VariableSymbol array without
  49.     // allocating or deallocting space. It may be invoked with an integer
  50.     // argument n which indicates the new size or with no argument which
  51.     // indicates that the size should be reset to 0.
  52.     //
  53.     void Reset(const int n = 0)
  54.     {
  55.         if (n < 0 || n > size)
  56.             assert(false);
  57.         top = n;
  58.     }
  59.  
  60.     //
  61.     // Return length of the VariableSymbol array.
  62.     //
  63.     int Length() { return top; }
  64.  
  65.     //
  66.     // Return a reference to the ith element of the VariableSymbol array.
  67.     //
  68.     // Note that no check is made here to ensure that 0 <= i < top.
  69.     // Such a check might be useful for debugging and a range exception
  70.     // should be thrown if it yields true.
  71.     //
  72.     T& operator[](const int i) { return base[i >> log_blksize][i]; }
  73.  
  74.     //
  75.     // Add an element to the VariableSymbol array and return the top index.
  76.     //
  77.     int NextIndex()
  78.     {
  79.         int i = top++;
  80.         if (i == size)
  81.             AllocateMoreSpace();
  82.         return i;
  83.     }
  84.  
  85.     //
  86.     // Add an element to the VariableSymbol array and return a reference to
  87.     // that new element.
  88.     //
  89.     T& Next() { int i = NextIndex(); return base[i >> log_blksize][i]; }
  90.  
  91.     //
  92.     // Constructor of a VariableSymbol array.
  93.     //
  94.     VariableSymbolArray(StoragePool *, unsigned);
  95.  
  96.     //
  97.     // Destructor of an VariableSymbol array.
  98.     //
  99.     ~VariableSymbolArray() { assert(false); }
  100. };
  101.  
  102.  
  103. //
  104. // Global function used when the space for a dynamic object is
  105. // preallocated, but we need to call a constructor to initialize the
  106. // space.
  107. //
  108. // inline static void *operator new(size_t, void *p) { return p; }
  109. //
  110.  
  111. //**********************************************************************************
  112. //
  113. // This file contains the definitions of the classes used to construct the
  114. // AST representation of a Java program.
  115. //
  116. // The node Ast is a base class of all other classes. (The name of the other classes
  117. // start with the prefix "Ast".) The nodes associated with executable statements
  118. // (e.g., AstIfStatement) are subclasses of AstStatement and nodes associated with
  119. // expressions (e.g., AstBinaryExpression) are subclasses of AstExpression.
  120. //
  121. // The information contained in the AST nodes is described by a grammar where
  122. // each rule consists of a left-hand side nonterminal followed by "-->" followed
  123. // by a right-hand side symbol or a sequence enclosed in the pair of symbols
  124. // "<" and ">". In defining the symbols, the following notation is used:
  125. //
  126. // Symbols that are capitalized (e.g., Type) are nonterminals. Symbols that are
  127. // in all upper case (e.g., PACKAGE) represent node kinds. Symbols that contain
  128. // the substring "_token" represents tokens in the source file. The suffix "_opt"
  129. // indicates that a symbol is optional. For example, if Super_opt appears in a
  130. // rule, it indicates that either Super or null can be expected. When a symbol
  131. // is plural (e.g., Modifiers), it indicates zero or more instances of such a
  132. // symbol (a list to be precise) can be expected. Thus, when "Modifiers" is
  133. // specified in the right-hand side of a rule either no Modifier or a sequence
  134. // of them may appear.
  135. //
  136. // Implementation Notes:
  137. //
  138. //    A complete AST tree for a Java program always contains an
  139. //    AstCompilationUnit root node. The kind of that node is
  140. //    Ast::EMPTY_COMPILATION for a tree with no type declaration,
  141. //    Ast::COMPILATION for a tree constructed from an otherwise valid program
  142. //    and Ast::BAD_COMPILATION for a tree constructed from an invalid program.
  143. //
  144. //    Since the AST is a tree data structure, each node contains a virtual
  145. //    destructor that can delete its subtrees. Therefore, a user can dispose of
  146. //    a whole ast tree (or subtree) by simply deleting the root node.
  147. //
  148. //    When the preprocessor variable TEST is defined the user may print out
  149. //    an AST tree to standard output by calling the virtual function "Print"
  150. //    for the root node of the tree.
  151. //
  152. //    DynamicArrays are used to implement lists. This representation has the
  153. //    advantage of being very flexible and easy to use. However, it may be slightly
  154. //    less time-efficient than a straightforward linked list. My guess is no more
  155. //    than 10% which justifies this use, but that should be checked at some point...
  156. //
  157. //**********************************************************************************
  158.  
  159. //
  160. // This is a complete list of all Ast nodes declared here to allow
  161. // forward references.
  162. //
  163. class Ast;
  164. class AstListNode;
  165. class AstStatement;
  166. class AstExpression;
  167. class AstPrimitiveType;
  168. class AstArrayType;
  169. class AstSimpleName;
  170. class AstPackageDeclaration;
  171. class AstImportDeclaration;
  172. class AstCompilationUnit;
  173. class AstModifier;
  174. class AstEmptyDeclaration;
  175. class AstClassDeclaration;
  176. class AstClassBody;
  177. class AstArrayInitializer;
  178. class AstBrackets;
  179. class AstVariableDeclaratorId;
  180. class AstVariableDeclarator;
  181. class AstFieldDeclaration;
  182. class AstFormalParameter;
  183. class AstMethodDeclarator;
  184. class AstMethodDeclaration;
  185. class AstStaticInitializer;
  186. class AstThisCall;
  187. class AstSuperCall;
  188. class AstConstructorBlock;
  189. class AstConstructorDeclaration;
  190. class AstInterfaceDeclaration;
  191. class AstBlock;
  192. class AstLocalVariableDeclarationStatement;
  193. class AstIfStatement;
  194. class AstEmptyStatement;
  195. class AstExpressionStatement;
  196. class AstCaseLabel;
  197. class AstDefaultLabel;
  198. class AstSwitchBlockStatement;
  199. class AstSwitchStatement;
  200. class AstWhileStatement;
  201. class AstDoStatement;
  202. class AstForStatement;
  203. class AstBreakStatement;
  204. class AstContinueStatement;
  205. class AstReturnStatement;
  206. class AstThrowStatement;
  207. class AstSynchronizedStatement;
  208. class AstCatchClause;
  209. class AstFinallyClause;
  210. class AstTryStatement;
  211. class AstIntegerLiteral;
  212. class AstLongLiteral;
  213. class AstFloatingPointLiteral;
  214. class AstDoubleLiteral;
  215. class AstTrueLiteral;
  216. class AstFalseLiteral;
  217. class AstStringLiteral;
  218. class AstCharacterLiteral;
  219. class AstNullLiteral;
  220. class AstThisExpression;
  221. class AstSuperExpression;
  222. class AstParenthesizedExpression;
  223. class AstClassInstanceCreationExpression;
  224. class AstDimExpr;
  225. class AstArrayCreationExpression;
  226. class AstFieldAccess;
  227. class AstMethodInvocation;
  228. class AstArrayAccess;
  229. class AstPostUnaryExpression;
  230. class AstPreUnaryExpression;
  231. class AstCastExpression;
  232. class AstBinaryExpression;
  233. class AstTypeExpression;
  234. class AstConditionalExpression;
  235. class AstAssignmentExpression;
  236.  
  237. class CaseElement;
  238.  
  239. //
  240. // The Ast base node.
  241. //
  242. class Ast
  243. {
  244. public:
  245.     //
  246.     // These tags are used to identify nodes that can represent more than
  247.     // one kind of objects.
  248.     //
  249.     enum AstTag
  250.     {
  251.         NO_TAG,
  252.         PRIMITIVE_TYPE,
  253.         STATEMENT,
  254.         EXPRESSION,
  255.         MODIFIER,
  256.         STATIC_FIELD,
  257.         UNPARSED,
  258.  
  259.         _num_tags = MODIFIER
  260.     };
  261.  
  262.     //
  263.     // These are the different kinds for the Ast objects.
  264.     //
  265.     enum AstKind
  266.     {
  267.         AST,
  268.         IDENTIFIER,
  269.         DOT,
  270.         INTEGER_LITERAL,
  271.         LONG_LITERAL,
  272.         FLOATING_POINT_LITERAL,
  273.         DOUBLE_LITERAL,
  274.         TRUE_LITERAL,
  275.         FALSE_LITERAL,
  276.         STRING_LITERAL,
  277.         CHARACTER_LITERAL,
  278.         NULL_LITERAL,
  279.         ARRAY_ACCESS,
  280.         CALL,
  281.         THIS_EXPRESSION,
  282.         SUPER_EXPRESSION,
  283.         PARENTHESIZED_EXPRESSION,
  284.         CLASS_CREATION,
  285.         ARRAY_CREATION,
  286.         POST_UNARY,
  287.         PRE_UNARY,
  288.         CAST,
  289.         CHECK_AND_CAST,
  290.         BINARY,
  291.         TYPE,
  292.         CONDITIONAL,
  293.         ASSIGNMENT,
  294.  
  295.         _num_expression_kinds,
  296.  
  297.         DIM = _num_expression_kinds,
  298.         LIST_NODE,
  299.         INT,
  300.         DOUBLE,
  301.         CHAR,
  302.         LONG,
  303.         FLOAT,
  304.         BYTE,
  305.         SHORT,
  306.         BOOLEAN,
  307.         VOID_TYPE,
  308.         ARRAY,
  309.         COMPILATION,
  310.         BAD_COMPILATION,
  311.         EMPTY_COMPILATION,
  312.         PACKAGE_COMPONENT,
  313.         PACKAGE_NAME,
  314.         PACKAGE,
  315.         IMPORT,
  316.         EMPTY_DECLARATION,
  317.         CLASS,
  318.         CLASS_BODY,
  319.         PUBLIC,
  320.         PROTECTED,
  321.         PRIVATE,
  322.         STATIC,
  323.         ABSTRACT,
  324.         FINAL,
  325.         NATIVE,
  326.         STRICTFP,
  327.         SYNCHRONIZED,
  328.         TRANSIENT,
  329.         VOLATILE,
  330.         FIELD,
  331.         VARIABLE_DECLARATOR,
  332.         VARIABLE_DECLARATOR_NAME,
  333.         BRACKETS,
  334.         METHOD,
  335.         METHOD_DECLARATOR,
  336.         PARAMETER,
  337.         CONSTRUCTOR,
  338.         INTERFACE,
  339.         ARRAY_INITIALIZER,
  340.         STATIC_INITIALIZER,
  341.         THIS_CALL,
  342.         SUPER_CALL,
  343.         BLOCK,
  344.         CONSTRUCTOR_BLOCK,
  345.         LOCAL_VARIABLE_DECLARATION,
  346.         IF,
  347.         EMPTY_STATEMENT,
  348.         EXPRESSION_STATEMENT,
  349.         SWITCH,
  350.         SWITCH_BLOCK,
  351.         CASE,
  352.         DEFAULT,
  353.         WHILE,
  354.         DO,
  355.         FOR,
  356.         BREAK,
  357.         CONTINUE,
  358.         RETURN,
  359.         THROW,
  360.         SYNCHRONIZED_STATEMENT,
  361.         TRY,
  362.         CATCH,
  363.         FINALLY,
  364.  
  365.         _num_kinds
  366.     };
  367.  
  368. #ifdef TEST
  369.     typedef AstKind Kind;
  370.     typedef AstTag  Tag;
  371. #else
  372.     typedef unsigned short Kind;
  373.     typedef unsigned char  Tag;
  374. #endif
  375.  
  376.     Kind  kind;      // every node has a unique kind...
  377.     Tag   class_tag; // Some subsets of nodes are grouped together to form a class of nodes.
  378.     bool  generated; // "generated" is a boolean value that indicates whether or not a node
  379.                      // is associated with a construct in a source file or that is was generated
  380.                      // by the compiler. See functions "gen_ ..." and "new_ ..." below.
  381.  
  382. #ifdef TEST
  383.     unsigned id;
  384.     static unsigned count;
  385.     static bool debug_unparse;
  386.  
  387.     Ast() : id(++count)
  388.     {}
  389. #endif
  390.  
  391.     virtual ~Ast();
  392.  
  393. #ifdef TEST
  394.     virtual void Print(LexStream &);
  395.     virtual void Unparse(Ostream &, LexStream &);
  396. #endif
  397.  
  398.     //
  399.     // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  400.     //
  401.     bool IsName();
  402.     bool IsSimpleNameOrFieldAccess();
  403.     bool IsSuperExpression();
  404.     bool IsLeftHandSide();
  405.     bool IsGenerated();
  406.  
  407.     //
  408.     // The Conversion functions below are provided as a convenient way to
  409.     // cast a generic Ast node into a specific node. Note that if one knows
  410.     // the type of a node for sure, it is more efficient to use a specific
  411.     // cast expression. For example, if one knows that a "Ast *p" pointer
  412.     // dereferences a FieldDeclaration then a cast expression should be
  413.     // used to cast p, as follows:
  414.     //
  415.     //       AstFieldDeclaration *fp = (FieldDeclaration *) p;
  416.     //
  417.     // However, if p points to a ClassBodyDeclaration which may be
  418.     // either a FieldDeclaration, MethodDeclaration, ConstructorDeclaration,
  419.     // StaticInitializer, ClassDeclaration, InterfaceDeclaration or a block
  420.     // then the following sequence of code may be used:
  421.     //
  422.     //    AstFieldDeclaration       *fp;
  423.     //    AstMethodDeclaration      *mp;
  424.     //    AstConstructorDeclaration *cp;
  425.     //    AstStaticInitializer      *sp;
  426.     //    AstClassDeclaration       *Cp; // 1.1 only
  427.     //    AstInterfaceDeclaration   *Ip; // 1.1 only
  428.     //    AstBlock                  *Bp; // 1.1 only
  429.     //
  430.     //    if (fp = p -> FieldDeclaration())
  431.     //        ...
  432.     //    else if (mp = p -> MethodDeclaration())
  433.     //        ...
  434.     //    else if (cp = p -> ConstructorDeclaration())
  435.     //        ...
  436.     //    else if (sp = p -> StaticInitializer())
  437.     //        ...
  438.     //    else if (Cp = p -> ClassDeclaration())
  439.     //        ...
  440.     //    else if (Ip = p -> InterfaceDeclaration())
  441.     //        ...
  442.     //    else if (Bp = p -> Block())
  443.     //        ...
  444.     //
  445.  
  446.     //
  447.     // These cast functions are used for classes that represent more than
  448.     // one kind of nodes.
  449.     //
  450.     AstStatement *StatementCast()                        { return (AstStatement *) (class_tag == STATEMENT ? this : NULL); }
  451.     AstExpression *ExpressionCast()                      { return (AstExpression *) (class_tag == EXPRESSION ? this : NULL); }
  452.     AstPrimitiveType *PrimitiveTypeCast()                { return (AstPrimitiveType *) (class_tag == PRIMITIVE_TYPE ? this : NULL); }
  453.     AstModifier *ModifierCast()                          { return (AstModifier *) (class_tag == MODIFIER ? this : NULL); }
  454.     AstFieldDeclaration *StaticFieldCast()               { return (AstFieldDeclaration *) (class_tag == STATIC_FIELD ? this : NULL); }
  455.     AstClassBody *UnparsedClassBodyCast()                { return (AstClassBody *) (class_tag == UNPARSED ? this : NULL); }
  456.     AstInterfaceDeclaration *UnparsedInterfaceBodyCast() { return (AstInterfaceDeclaration *) (class_tag == UNPARSED ? this : NULL); }
  457.  
  458.     //
  459.     // These cast functions are used for classes that represent exactly
  460.     // one kind of node.
  461.     //
  462.     AstListNode *ListNodeCast() { return (AstListNode *) (kind == LIST_NODE ? this : NULL); }
  463.     AstArrayType *ArrayTypeCast() { return (AstArrayType *) (kind == ARRAY ? this : NULL); }
  464.     AstSimpleName *SimpleNameCast() { return (AstSimpleName *) (kind == IDENTIFIER ? this : NULL); }
  465.     AstPackageDeclaration *PackageDeclarationCast() { return (AstPackageDeclaration *) (kind == PACKAGE ? this : NULL); }
  466.     AstImportDeclaration *ImportDeclarationCast() { return (AstImportDeclaration *) (kind == IMPORT ? this : NULL); }
  467.     AstCompilationUnit *CompilationUnitCast()
  468.       { return (AstCompilationUnit *) (kind == COMPILATION || kind == BAD_COMPILATION || kind == EMPTY_COMPILATION ? this : NULL); }
  469.     AstCompilationUnit *BadCompilationUnitCast() { return (AstCompilationUnit *) (kind == BAD_COMPILATION ? this : NULL); }
  470.     AstCompilationUnit *EmptyCompilationUnitCast() { return (AstCompilationUnit *) (kind == EMPTY_COMPILATION ? this : NULL); }
  471.     AstEmptyDeclaration *EmptyDeclarationCast() { return (AstEmptyDeclaration *) (kind == EMPTY_DECLARATION ? this : NULL); }
  472.     AstClassDeclaration *ClassDeclarationCast() { return (AstClassDeclaration *) (kind == CLASS ? this : NULL); }
  473.     AstArrayInitializer *ArrayInitializerCast() { return (AstArrayInitializer *) (kind == ARRAY_INITIALIZER ? this : NULL); }
  474.     AstBrackets *BracketsCast() { return (AstBrackets *) (kind == BRACKETS ? this : NULL); }
  475.     AstVariableDeclaratorId *VariableDeclaratorIdCast()
  476.         { return (AstVariableDeclaratorId *) (kind == VARIABLE_DECLARATOR_NAME ? this : NULL); }
  477.     AstVariableDeclarator *VariableDeclaratorCast()
  478.         { return (AstVariableDeclarator *) (kind == VARIABLE_DECLARATOR ? this : NULL); }
  479.     AstFieldDeclaration *FieldDeclarationCast() { return (AstFieldDeclaration *) (kind == FIELD ? this : NULL); }
  480.     AstFormalParameter *FormalParameterCast() { return (AstFormalParameter *) (kind == PARAMETER ? this : NULL); }
  481.     AstMethodDeclarator *MethodDeclaratorCast() { return (AstMethodDeclarator *) (kind == METHOD_DECLARATOR ? this : NULL); }
  482.     AstMethodDeclaration *MethodDeclarationCast() { return (AstMethodDeclaration *) (kind == METHOD ? this : NULL); }
  483.     AstStaticInitializer *StaticInitializerCast()
  484.         { return (AstStaticInitializer *) (kind == STATIC_INITIALIZER ? this : NULL); }
  485.     AstThisCall *ThisCallCast() { return (AstThisCall *) (kind == THIS_CALL ? this : NULL); }
  486.     AstSuperCall *SuperCallCast() { return (AstSuperCall *) (kind == SUPER_CALL ? this : NULL); }
  487.     AstConstructorBlock *ConstructorBlockCast()
  488.         { return (AstConstructorBlock *) (kind == CONSTRUCTOR_BLOCK ? this : NULL); }
  489.     AstConstructorDeclaration *ConstructorDeclarationCast()
  490.         { return (AstConstructorDeclaration *) (kind == CONSTRUCTOR ? this : NULL); }
  491.     AstInterfaceDeclaration *InterfaceDeclarationCast()
  492.         { return (AstInterfaceDeclaration *) (kind == INTERFACE ? this : NULL); }
  493.     AstBlock *BlockCast() { return (AstBlock *) (kind == BLOCK ? this : NULL); }
  494.     AstLocalVariableDeclarationStatement *LocalVariableDeclarationStatementCast()
  495.         { return (AstLocalVariableDeclarationStatement *) (kind == LOCAL_VARIABLE_DECLARATION ? this : NULL); }
  496.     AstIfStatement *IfStatementCast() { return (AstIfStatement *) (kind == IF ? this : NULL); }
  497.     AstEmptyStatement *EmptyStatementCast() { return (AstEmptyStatement *) (kind == EMPTY_STATEMENT ? this : NULL); }
  498.     AstExpressionStatement *ExpressionStatementCast()
  499.         { return (AstExpressionStatement *) (kind == EXPRESSION_STATEMENT ? this : NULL); }
  500.     AstCaseLabel *CaseLabelCast() { return (AstCaseLabel *) (kind == CASE ? this : NULL); }
  501.     AstDefaultLabel *DefaultLabelCast() { return (AstDefaultLabel *) (kind == DEFAULT ? this : NULL); }
  502.     AstSwitchBlockStatement *SwitchBlockStatementCast()
  503.         { return (AstSwitchBlockStatement *) (kind == SWITCH_BLOCK ? this : NULL); }
  504.     AstSwitchStatement *SwitchStatementCast() { return (AstSwitchStatement *) (kind == SWITCH ? this : NULL); }
  505.     AstWhileStatement *WhileStatementCast() { return (AstWhileStatement *) (kind == WHILE ? this : NULL); }
  506.     AstDoStatement *DoStatementCast() { return (AstDoStatement *) (kind == DO ? this : NULL); }
  507.     AstForStatement *ForStatementCast() { return (AstForStatement *) (kind == FOR ? this : NULL); }
  508.     AstBreakStatement *BreakStatementCast() { return (AstBreakStatement *) (kind == BREAK ? this : NULL); }
  509.     AstContinueStatement *ContinueStatementCast() { return (AstContinueStatement *) (kind == CONTINUE ? this : NULL); }
  510.     AstReturnStatement *ReturnStatementCast() { return (AstReturnStatement *) (kind == RETURN ? this : NULL); }
  511.     AstThrowStatement *ThrowStatementCast() { return (AstThrowStatement *) (kind == THROW ? this : NULL); }
  512.     AstSynchronizedStatement *SynchronizedStatementCast()
  513.         { return (AstSynchronizedStatement *) (kind == SYNCHRONIZED_STATEMENT ? this : NULL); }
  514.     AstCatchClause *CatchClauseCast() { return (AstCatchClause *) (kind == CATCH ? this : NULL); }
  515.     AstFinallyClause *FinallyClauseCast() { return (AstFinallyClause *) (kind == FINALLY ? this : NULL); }
  516.     AstTryStatement *TryStatementCast() { return (AstTryStatement *) (kind == TRY ? this : NULL); }
  517.     AstIntegerLiteral *IntegerLiteralCast() { return (AstIntegerLiteral *) (kind == INTEGER_LITERAL ? this : NULL); }
  518.     AstLongLiteral *LongLiteralCast() { return (AstLongLiteral *) (kind == LONG_LITERAL ? this : NULL); }
  519.     AstFloatingPointLiteral *FloatingPointLiteralCast()
  520.         { return (AstFloatingPointLiteral *) (kind == FLOATING_POINT_LITERAL ? this : NULL); }
  521.     AstDoubleLiteral *DoubleLiteralCast() { return (AstDoubleLiteral *) (kind == DOUBLE_LITERAL ? this : NULL); }
  522.     AstTrueLiteral *TrueLiteralCast() { return (AstTrueLiteral *) (kind == TRUE_LITERAL ? this : NULL); }
  523.     AstFalseLiteral *FalseLiteralCast() { return (AstFalseLiteral *) (kind == FALSE_LITERAL ? this : NULL); }
  524.     AstStringLiteral *StringLiteralCast() { return (AstStringLiteral *) (kind == STRING_LITERAL ? this : NULL); }
  525.     AstCharacterLiteral *CharacterLiteralCast() { return (AstCharacterLiteral *) (kind == CHARACTER_LITERAL ? this : NULL); }
  526.     AstNullLiteral *NullLiteralCast() { return (AstNullLiteral *) (kind == NULL_LITERAL ? this : NULL); }
  527.     AstThisExpression *ThisExpressionCast() { return (AstThisExpression *) (kind == THIS_EXPRESSION ? this : NULL); }
  528.     AstSuperExpression *SuperExpressionCast() { return (AstSuperExpression *) (kind == SUPER_EXPRESSION ? this : NULL); }
  529.     AstParenthesizedExpression *ParenthesizedExpressionCast()
  530.         { return (AstParenthesizedExpression *) (kind == PARENTHESIZED_EXPRESSION ? this : NULL); }
  531.     AstClassInstanceCreationExpression *ClassInstanceCreationExpressionCast()
  532.         { return (AstClassInstanceCreationExpression *) (kind == CLASS_CREATION ? this : NULL); }
  533.     AstDimExpr *DimExprCast() { return (AstDimExpr *) (kind == DIM ? this : NULL); }
  534.     AstArrayCreationExpression *ArrayCreationExpressionCast()
  535.         { return (AstArrayCreationExpression *) (kind == ARRAY_CREATION ? this : NULL); }
  536.     AstFieldAccess *FieldAccessCast() { return (AstFieldAccess *) (kind == DOT ? this : NULL); }
  537.     AstMethodInvocation *MethodInvocationCast() { return (AstMethodInvocation *) (kind == CALL ? this : NULL); }
  538.     AstArrayAccess *ArrayAccessCast() { return (AstArrayAccess *) (kind == ARRAY_ACCESS ? this : NULL); }
  539.     AstPostUnaryExpression *PostUnaryExpressionCast()
  540.         { return (AstPostUnaryExpression *) (kind == POST_UNARY ? this : NULL); }
  541.     AstPreUnaryExpression *PreUnaryExpressionCast()
  542.         { return (AstPreUnaryExpression *) (kind == PRE_UNARY ? this : NULL); }
  543.     AstCastExpression *CastExpressionCast() { return (AstCastExpression *) (kind == CAST || kind == CHECK_AND_CAST ? this : NULL); }
  544.     AstBinaryExpression *BinaryExpressionCast() { return (AstBinaryExpression *) (kind == BINARY ? this : NULL); }
  545.     AstTypeExpression *TypeExpressionCast() { return (AstTypeExpression *) (kind == TYPE ? this : NULL); }
  546.     AstConditionalExpression *ConditionalExpressionCast()
  547.         { return (AstConditionalExpression *) (kind == CONDITIONAL ? this : NULL); }
  548.     AstAssignmentExpression *AssignmentExpressionCast()
  549.         { return (AstAssignmentExpression *) (kind == ASSIGNMENT ? this : NULL); }
  550.  
  551.     virtual Ast *Clone(StoragePool *);
  552.  
  553.     virtual LexStream::TokenIndex LeftToken()  { assert(0); return 0; }
  554.     virtual LexStream::TokenIndex RightToken() { assert(0); return 0; }
  555. };
  556.  
  557.  
  558. //
  559. // This AstArray template class can be used to construct a dynamic
  560. // array of arbitrary objects. The space for the array is allocated in
  561. // blocks of size 2**LOG_BLKSIZE. In declaring a Ast array the user
  562. // may specify a value for LOG_BLKSIZE which by default is 6. Also,
  563. // as the array is implemented using a base+offset strategy, the user
  564. // may also specify the number of "slots" to add to the base when the
  565. // current base runs out of space. Each slot points to a block.
  566. //
  567. template <class T>
  568. class AstArray
  569. {
  570.     T **base;
  571.     size_t base_size;
  572.     int top,
  573.         size;
  574.     StoragePool *pool;
  575.     unsigned short log_blksize,
  576.                    base_increment;
  577.  
  578.     inline size_t Blksize() { return (1 << log_blksize); }
  579.  
  580.     //
  581.     // Allocate another block of storage for the Ast array.
  582.     //
  583.     void AllocateMoreSpace();
  584.  
  585. public:
  586.  
  587.     //
  588.     // This function is used to reset the size of a Ast array without
  589.     // allocating or deallocting space. It may be invoked with an integer
  590.     // argument n which indicates the new size or with no argument which
  591.     // indicates that the size should be reset to 0.
  592.     //
  593.     void Reset(const int n = 0)
  594.     {
  595.         if (n < 0 || n > size)
  596.             assert(false);
  597.         top = n;
  598.     }
  599.  
  600.     //
  601.     // Return length of the Ast array.
  602.     //
  603.     int Length() { return top; }
  604.  
  605.     //
  606.     // Return a reference to the ith element of the Ast array.
  607.     //
  608.     // Note that no check is made here to ensure that 0 <= i < top.
  609.     // Such a check might be useful for debugging and a range exception
  610.     // should be thrown if it yields true.
  611.     //
  612.     T& operator[](const int i) { return base[i >> log_blksize][i]; }
  613.  
  614.     //
  615.     // Add an element to the Ast array and return the top index.
  616.     //
  617.     int NextIndex()
  618.     {
  619.         int i = top++;
  620.         if (i == size)
  621.             AllocateMoreSpace();
  622.         return i;
  623.     }
  624.  
  625.     //
  626.     // Add an element to the Ast array and return a reference to
  627.     // that new element.
  628.     //
  629.     T& Next() { int i = NextIndex(); return base[i >> log_blksize][i]; }
  630.  
  631.     inline void Push(T elt) { this -> Next() = elt; }
  632.     // Not "return (*this)[--top]" because that may violate an invariant
  633.     // in operator[].
  634.     inline T Pop() { assert(top!=0); top--; return base[top >> log_blksize][top]; }
  635.     inline T Top() { assert(top!=0); return (*this)[top-1]; }
  636.  
  637.     //
  638.     // Constructor of a ast array.
  639.     //
  640.     AstArray(StoragePool *, unsigned);
  641.  
  642.     //
  643.     // Destructor of an Ast array.
  644.     //
  645.     ~AstArray() { assert(false); }
  646. };
  647.  
  648.  
  649. //
  650. // The Ast base node.
  651. //
  652. class AstListNode : public Ast
  653. {
  654. public:
  655.     AstListNode *next;
  656.     Ast *element;
  657.     unsigned index;
  658.  
  659.     AstListNode()
  660.     {
  661.         Ast::kind = Ast::LIST_NODE;
  662.         Ast::class_tag = Ast::NO_TAG;
  663.         Ast::generated = 0;
  664. #ifdef TEST
  665.         --count; // don't count these nodes
  666. #endif
  667.     }
  668.  
  669.     ~AstListNode() {}
  670.  
  671.     virtual LexStream::TokenIndex LeftToken()  { return element -> LeftToken(); }
  672.     virtual LexStream::TokenIndex RightToken() { return element -> RightToken(); }
  673. };
  674.  
  675.  
  676. class AstStatement : public Ast
  677. {
  678. protected:
  679.  
  680.     StoragePool *pool;
  681.     VariableSymbolArray *defined_variables;
  682.  
  683. public:
  684.  
  685.     bool is_reachable,
  686.          can_complete_normally;
  687.  
  688.     //
  689.     // Note that for efficiency reasons AstStatement does not have a constructor.
  690.     // Therefore, subclasses that are derived from AstStatement are expected to
  691.     // initialize the fields is_reachable and can_complete_normally appropriately.
  692.     //
  693.     // Note also that an AstStatement is never constructed directly!
  694.     //
  695.     virtual ~AstStatement();
  696.  
  697.     virtual Ast *Clone(StoragePool *) { return (Ast *) NULL; }
  698.  
  699.     inline VariableSymbol *&DefinedVariable(int i) { return (*defined_variables)[i]; }
  700.     inline int NumDefinedVariables() { return (defined_variables ? defined_variables -> Length() : 0); }
  701.     inline void AllocateDefinedVariables(int estimate = 0);
  702.     inline void AddDefinedVariable(VariableSymbol *);
  703.  
  704.     virtual LexStream::TokenIndex LeftToken()  { assert(0); return 0; }
  705.     virtual LexStream::TokenIndex RightToken() { assert(0); return 0; }
  706. };
  707.  
  708.  
  709. class AstExpression : public Ast
  710. {
  711. public:
  712.     LiteralValue *value;
  713.     Symbol *symbol;
  714.  
  715.     //
  716.     // Note that for efficiency reasons AstExpression does not have a constructor.
  717.     // However, subclasses that are derived from AstExpression are expected to
  718.     // initialize the fields value and symbol to NULL as indicated below:
  719.     //
  720.     // AstExpression() : value(NULL),
  721.     //                   symbol(NULL)
  722.     // {}
  723.     //
  724.  
  725.     virtual ~AstExpression();
  726.  
  727.     bool IsConstant() { return (value != NULL); }
  728.  
  729.     TypeSymbol *Type()
  730.     {
  731.         return (TypeSymbol *)
  732.                (symbol ? (symbol -> Kind() == Symbol::TYPE
  733.                                   ? (TypeSymbol *) symbol
  734.                                   : (symbol -> Kind() == Symbol::VARIABLE
  735.                                              ? ((VariableSymbol *) symbol) -> Type()
  736.                                              : (symbol -> Kind() == Symbol::METHOD
  737.                                                         ? ((MethodSymbol *) symbol) -> Type()
  738.                                                         : NULL)))
  739.                        : NULL);
  740.     }
  741.  
  742.     virtual Ast *Clone(StoragePool *) { return (Ast *) NULL; }
  743.  
  744.     virtual LexStream::TokenIndex LeftToken()  { assert(0); return 0; }
  745.     virtual LexStream::TokenIndex RightToken() { assert(0); return 0; }
  746. };
  747.  
  748.  
  749. //
  750. // Block --> <BLOCK, {_token, BlockStatements, }_token>
  751. //
  752. // BlockStatement --> LocalVariableDeclarationStatement
  753. //                  | Statement
  754. //
  755. class AstBlock : public AstStatement
  756. {
  757. private:
  758.  
  759.     AstArray<LexStream::TokenIndex> *labels;
  760.     AstArray<Ast *> *block_statements;
  761.     VariableSymbolArray *locally_defined_variables;
  762.  
  763. public:
  764.     enum BlockTag
  765.     {
  766.         NONE,
  767.         TRY_CLAUSE_WITH_FINALLY,
  768.         FINALLY,
  769.         SYNCHRONIZED
  770.     };
  771.     BlockTag block_tag;
  772.  
  773.     BlockSymbol *block_symbol;
  774.  
  775.     int nesting_level;
  776.     LexStream::TokenIndex left_brace_token;
  777.     LexStream::TokenIndex right_brace_token;
  778.  
  779.     bool no_braces;
  780.  
  781.     AstBlock(StoragePool *pool_) : labels(NULL),
  782.                                    block_statements(NULL),
  783.                                    locally_defined_variables(NULL),
  784.                                    block_tag(NONE),
  785.                                    block_symbol(NULL),
  786.                                    nesting_level(0),
  787.                    no_braces(false)
  788.     {
  789.         Ast::kind = Ast::BLOCK;
  790.         Ast::class_tag = Ast::STATEMENT;
  791.         Ast::generated = 0;
  792.         AstStatement::pool = pool_;
  793.         AstStatement::is_reachable = false;
  794.         AstStatement::can_complete_normally = false;
  795.         AstStatement::defined_variables = NULL;
  796.     }
  797.  
  798.     virtual ~AstBlock();
  799.  
  800.     inline Ast *&Statement(int i) { return (*block_statements)[i]; }
  801.     inline int NumStatements() { return (block_statements ? block_statements -> Length() : 0); }
  802.     inline void AllocateBlockStatements(int estimate = 0);
  803.     inline void AddStatement(Ast *);
  804.  
  805.     inline LexStream::TokenIndex &Label(int i) { return (*labels)[i]; }
  806.     inline int NumLabels() { return (labels ? labels -> Length() : 0); }
  807.     inline void AllocateLabels(int estimate = 4);
  808.     inline void AddLabel(LexStream::TokenIndex);
  809.  
  810.     inline VariableSymbol *&LocallyDefinedVariable(int i) { return (*locally_defined_variables)[i]; }
  811.     inline int NumLocallyDefinedVariables() { return (locally_defined_variables ? locally_defined_variables -> Length() : 0); }
  812.     inline void AllocateLocallyDefinedVariables(int estimate = 0);
  813.     inline void AddLocallyDefinedVariable(VariableSymbol *);
  814.  
  815.     inline void TransferLocallyDefinedVariablesTo(AstSwitchBlockStatement *);
  816.  
  817. #ifdef TEST
  818.     virtual void Print(LexStream &);
  819.     virtual void Unparse(Ostream &, LexStream &);
  820. #endif
  821.  
  822.     virtual Ast *Clone(StoragePool *);
  823.  
  824.     virtual LexStream::TokenIndex LeftToken()  { return left_brace_token; }
  825.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  826. };
  827.  
  828. //
  829. // Type --> PrimitiveType
  830. //        | ReferenceType
  831. //
  832. // PrimitiveType --> <PrimitiveKind, PrimitiveName>
  833. //
  834. // PrimitiveKind --> BYTE | SHORT | INT | LONG | CHAR | FLOAT | DOUBLE | BOOLEAN | VOID
  835. //
  836. // PrimitiveName --> byte_token | short_token | int_token | long_token |
  837. //                   char_token | float_token | double_token | boolean_token | void_token
  838. //
  839. class AstPrimitiveType : public Ast
  840. {
  841. public:
  842.     LexStream::TokenIndex primitive_kind_token;
  843.  
  844.     AstPrimitiveType(Ast::Kind kind_, LexStream::TokenIndex token_) : primitive_kind_token(token_)
  845.     {
  846.         Ast::kind = kind_;
  847.         Ast::class_tag = Ast::PRIMITIVE_TYPE;
  848.         Ast::generated = 0;
  849.     }
  850.  
  851.     virtual ~AstPrimitiveType();
  852.  
  853. #ifdef TEST
  854.     virtual void Print(LexStream &);
  855.     virtual void Unparse(Ostream &, LexStream &);
  856. #endif
  857.  
  858.     virtual Ast *Clone(StoragePool *);
  859.  
  860.     virtual LexStream::TokenIndex LeftToken()  { return primitive_kind_token; }
  861.     virtual LexStream::TokenIndex RightToken() { return primitive_kind_token; }
  862. };
  863.  
  864.  
  865. //
  866. // Brackets --> <BRACKETS, [_token, ]_token>
  867. //
  868. class AstBrackets : public Ast
  869. {
  870. public:
  871.     LexStream::TokenIndex left_bracket_token;
  872.     LexStream::TokenIndex right_bracket_token;
  873.  
  874.     AstBrackets(LexStream::TokenIndex left_, LexStream::TokenIndex right_) : left_bracket_token(left_),
  875.                                                                              right_bracket_token(right_)
  876.     {
  877.         Ast::kind = Ast::BRACKETS;
  878.         Ast::class_tag = Ast::NO_TAG;
  879.         Ast::generated = 0;
  880.     }
  881.  
  882.     virtual ~AstBrackets();
  883.  
  884. #ifdef TEST
  885.     virtual void Print(LexStream &);
  886.     virtual void Unparse(Ostream &, LexStream &);
  887. #endif
  888.  
  889.     virtual Ast *Clone(StoragePool *);
  890.  
  891.     virtual LexStream::TokenIndex LeftToken()  { return left_bracket_token; }
  892.     virtual LexStream::TokenIndex RightToken() { return right_bracket_token; }
  893. };
  894.  
  895.  
  896. //
  897. // ReferenceType --> ClassType
  898. //                 | ArrayType
  899. //
  900. // ClassType --> Name
  901. //
  902. // ArrayType --> <ARRAY, ArrayKind, [_token, ]_token>
  903. //
  904. // ArrayKind --> PrimitiveType
  905. //             | Name
  906. //             | ArrayType
  907. //
  908. class AstArrayType : public Ast
  909. {
  910. private:
  911.  
  912.     StoragePool *pool;
  913.     AstArray<AstBrackets *> *brackets;
  914.  
  915. public:
  916.     Ast *type;
  917.  
  918.     AstArrayType(StoragePool *pool_) : pool(pool_),
  919.                                        brackets(NULL)
  920.     {
  921.         Ast::kind = Ast::ARRAY;
  922.         Ast::class_tag = Ast::NO_TAG;
  923.         Ast::generated = 0;
  924.     }
  925.  
  926.     virtual ~AstArrayType();
  927.  
  928.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  929.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  930.     inline void AllocateBrackets(int estimate = 0);
  931.     inline void AddBrackets(AstBrackets *);
  932.  
  933. #ifdef TEST
  934.     virtual void Print(LexStream &);
  935.     virtual void Unparse(Ostream &, LexStream &);
  936. #endif
  937.  
  938.     virtual Ast *Clone(StoragePool *);
  939.  
  940.     virtual LexStream::TokenIndex LeftToken()  { return type -> LeftToken(); }
  941.     virtual LexStream::TokenIndex RightToken() { return Brackets(NumBrackets() - 1) -> RightToken(); }
  942. };
  943.  
  944.  
  945. //
  946. // Name --> SimpleName
  947. //        | FieldAccess
  948. //
  949. // SimpleName --> <IDENTIFIER, identifier_token>
  950. //
  951. class AstSimpleName : public AstExpression
  952. {
  953. public:
  954.     LexStream::TokenIndex identifier_token;
  955.  
  956.     //
  957.     // When a simple_name refers to a member in an enclosing scope,
  958.     // it is mapped into a new expression that creates a path to
  959.     // the member in question.
  960.     //
  961.     AstExpression *resolution_opt;
  962.  
  963.     AstSimpleName(LexStream::TokenIndex token_) : identifier_token(token_),
  964.                                                   resolution_opt(NULL)
  965.     {
  966.         Ast::kind = Ast::IDENTIFIER;
  967.         Ast::class_tag = Ast::EXPRESSION;
  968.         Ast::generated = 0;
  969.         AstExpression::value = NULL;
  970.         AstExpression::symbol = NULL;
  971.     }
  972.  
  973.     virtual ~AstSimpleName();
  974.  
  975. #ifdef TEST
  976.     virtual void Print(LexStream &);
  977.     virtual void Unparse(Ostream &, LexStream &);
  978. #endif
  979.  
  980.     virtual Ast *Clone(StoragePool *);
  981.  
  982.     virtual LexStream::TokenIndex LeftToken()  { return identifier_token; }
  983.     virtual LexStream::TokenIndex RightToken() { return identifier_token; }
  984. };
  985.  
  986. //
  987. // PackageDeclaration --> <PACKAGE, package_token, Name, ;_token>
  988. //
  989. class AstPackageDeclaration : public Ast
  990. {
  991. public:
  992.     LexStream::TokenIndex package_token;
  993.     AstExpression *name;
  994.     LexStream::TokenIndex semicolon_token;
  995.  
  996.     AstPackageDeclaration()
  997.     {
  998.         Ast::kind = Ast::PACKAGE;
  999.         Ast::class_tag = Ast::NO_TAG;
  1000.         Ast::generated = 0;
  1001.     }
  1002.  
  1003.     virtual ~AstPackageDeclaration();
  1004.  
  1005. #ifdef TEST
  1006.     virtual void Print(LexStream &);
  1007.     virtual void Unparse(Ostream &, LexStream &);
  1008. #endif
  1009.  
  1010.     virtual Ast *Clone(StoragePool *);
  1011.  
  1012.     virtual LexStream::TokenIndex LeftToken()  { return package_token; }
  1013.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1014. };
  1015.  
  1016. //
  1017. // ImportDeclaration --> <IMPORT, import_token, Name, *_token_opt, ;_token>
  1018. //
  1019. class AstImportDeclaration : public Ast
  1020. {
  1021. public:
  1022.     LexStream::TokenIndex import_token;
  1023.     AstExpression *name;
  1024.     LexStream::TokenIndex star_token_opt;       // import on demand
  1025.     LexStream::TokenIndex semicolon_token;
  1026.  
  1027.     AstImportDeclaration()
  1028.     {
  1029.         Ast::kind = Ast::IMPORT;
  1030.         Ast::class_tag = Ast::NO_TAG;
  1031.         Ast::generated = 0;
  1032.     }
  1033.  
  1034.     virtual ~AstImportDeclaration();
  1035.  
  1036. #ifdef TEST
  1037.     virtual void Print(LexStream &);
  1038.     virtual void Unparse(Ostream &, LexStream &);
  1039. #endif
  1040.  
  1041.     virtual Ast *Clone(StoragePool *);
  1042.  
  1043.     virtual LexStream::TokenIndex LeftToken()  { return import_token; }
  1044.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1045. };
  1046.  
  1047. //
  1048. // CompilationUnit --> <COMPILATION,     PackageDeclaration_opt, ImportDeclarations, TypeDeclarations>
  1049. //                   | <BAD_COMPILATION, PackageDeclaration_opt, ImportDeclarations, TypeDeclarations>
  1050. //                   | <EMPTY_COMPILATION, PackageDeclaration_opt, ImportDeclarations, TypeDeclarations>
  1051. //
  1052. class AstCompilationUnit : public Ast
  1053. {
  1054. private:
  1055.  
  1056.     StoragePool *pool;
  1057.     AstArray<AstImportDeclaration *> *import_declarations;
  1058.     AstArray<Ast *> *type_declarations;
  1059.  
  1060. public:
  1061.     StoragePool *ast_pool;
  1062.  
  1063.     AstPackageDeclaration *package_declaration_opt;
  1064.  
  1065.     AstCompilationUnit(StoragePool *pool_) : pool(pool_),
  1066.                                              import_declarations(NULL),
  1067.                                              type_declarations(NULL)
  1068.     {
  1069.         Ast::kind = Ast::COMPILATION;
  1070.         Ast::class_tag = Ast::NO_TAG;
  1071.         Ast::generated = 0;
  1072.     }
  1073.  
  1074.     virtual ~AstCompilationUnit();
  1075.  
  1076.     void FreeAst();
  1077.  
  1078.     inline AstImportDeclaration *&ImportDeclaration(int i) { return (*import_declarations)[i]; }
  1079.     inline int NumImportDeclarations() { return (import_declarations ? import_declarations -> Length() : 0); }
  1080.     inline void AllocateImportDeclarations(int estimate = 0);
  1081.     inline void AddImportDeclaration(AstImportDeclaration *);
  1082.  
  1083.     inline void ResetTypeDeclarations(int n) { if (type_declarations) type_declarations -> Reset(n); }
  1084.     inline Ast *&TypeDeclaration(int i) { return (*type_declarations)[i]; }
  1085.     inline int NumTypeDeclarations() { return (type_declarations ? type_declarations -> Length() : 0); }
  1086.     inline void AllocateTypeDeclarations(int estimate = 0);
  1087.     inline void AddTypeDeclaration(Ast *);
  1088.  
  1089. #ifdef TEST
  1090.     virtual void Print(LexStream &);
  1091.     virtual void Unparse(LexStream &, char * directory); // special form
  1092.     virtual void Unparse(Ostream &, LexStream &);
  1093. #endif
  1094.  
  1095.     virtual Ast *Clone(StoragePool *);
  1096.  
  1097.     virtual LexStream::TokenIndex LeftToken()
  1098.     {
  1099.         if (package_declaration_opt)
  1100.              return package_declaration_opt -> LeftToken();
  1101.         else if (NumImportDeclarations() > 0)
  1102.              return ImportDeclaration(0) -> LeftToken();
  1103.         else if (NumTypeDeclarations() > 0)
  1104.              return TypeDeclaration(0) -> LeftToken();
  1105.  
  1106.         return 0;
  1107.     }
  1108.  
  1109.     virtual LexStream::TokenIndex RightToken()
  1110.     {
  1111.         if (NumTypeDeclarations() > 0)
  1112.              return TypeDeclaration(NumTypeDeclarations() - 1) -> RightToken();
  1113.         else if (NumImportDeclarations() > 0)
  1114.              return ImportDeclaration(NumImportDeclarations() - 1) -> RightToken();
  1115.         else if (package_declaration_opt)
  1116.              return package_declaration_opt -> RightToken();
  1117.  
  1118.         return 0;
  1119.     }
  1120. };
  1121.  
  1122.  
  1123. //
  1124. // Modifier --> <ModifierKind, ModifierName>
  1125. //
  1126. // ModifierKind --> PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | NATIVE
  1127. //                  SYNCHRONIZED | TRANSIENT | VOLATILE
  1128. //
  1129. // ModifierName --> public_token | protected_token | private_token | static_token | abstract_token |
  1130. //                  final_token | native_token | synchronized_token | transient_token | volatile_token
  1131. //
  1132. class AstModifier : public Ast
  1133. {
  1134. public:
  1135.     LexStream::TokenIndex modifier_kind_token;
  1136.  
  1137.     AstModifier(Ast::Kind kind_, LexStream::TokenIndex token_) : modifier_kind_token(token_)
  1138.     {
  1139.         Ast::kind = kind_;
  1140.         Ast::class_tag = Ast::MODIFIER;
  1141.         Ast::generated = 0;
  1142.     }
  1143.  
  1144.     virtual ~AstModifier();
  1145.  
  1146. #ifdef TEST
  1147.     virtual void Print(LexStream &);
  1148.     virtual void Unparse(Ostream &, LexStream &);
  1149. #endif
  1150.  
  1151.     virtual Ast *Clone(StoragePool *);
  1152.  
  1153.     virtual LexStream::TokenIndex LeftToken()  { return modifier_kind_token; }
  1154.     virtual LexStream::TokenIndex RightToken() { return modifier_kind_token; }
  1155. };
  1156.  
  1157.  
  1158. //
  1159. // EmptyDeclaration --> <EMPTY_DECLARATION, ;_token>
  1160. //
  1161. class AstEmptyDeclaration : public Ast
  1162. {
  1163. public:
  1164.     LexStream::TokenIndex semicolon_token;
  1165.  
  1166.     AstEmptyDeclaration(LexStream::TokenIndex token_) : semicolon_token(token_)
  1167.     {
  1168.         Ast::kind = Ast::EMPTY_DECLARATION;
  1169.         Ast::class_tag = Ast::NO_TAG;
  1170.         Ast::generated = 0;
  1171.     }
  1172.  
  1173.     virtual ~AstEmptyDeclaration();
  1174.  
  1175. #ifdef TEST
  1176.     virtual void Print(LexStream &);
  1177.     virtual void Unparse(Ostream &, LexStream &);
  1178. #endif
  1179.  
  1180.     virtual Ast *Clone(StoragePool *);
  1181.  
  1182.     virtual LexStream::TokenIndex LeftToken() { return semicolon_token; }
  1183.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1184. };
  1185.  
  1186. //
  1187. // ClassBody --> <CLASS_BODY, {_token, ClassBodyDeclarations, }_token>
  1188. //
  1189. class AstClassBody : public Ast
  1190. {
  1191. private:
  1192.     friend class Parser;
  1193.  
  1194.     StoragePool *pool;
  1195.     AstArray<Ast *> *class_body_declarations;
  1196.  
  1197.     AstArray<AstFieldDeclaration *> *instance_variables;
  1198.     AstArray<AstFieldDeclaration *> *class_variables;
  1199.     AstArray<AstMethodDeclaration *> *methods;
  1200.     AstArray<AstConstructorDeclaration *> *constructors;
  1201.     AstArray<AstStaticInitializer *> *static_initializers;
  1202.     AstArray<AstClassDeclaration *> *inner_classes;
  1203.     AstArray<AstInterfaceDeclaration *> *inner_interfaces;
  1204.     AstArray<AstBlock *> *blocks;
  1205.     AstArray<AstEmptyDeclaration *> *empty_declarations;
  1206.  
  1207. public:
  1208.  
  1209.     AstConstructorDeclaration *default_constructor;
  1210.  
  1211.     AstBlock *this_block; // used by inner classes to initialize this$1, ...this$n fields
  1212.  
  1213.     LexStream::TokenIndex left_brace_token;
  1214.     LexStream::TokenIndex right_brace_token;
  1215.  
  1216.     inline void mark_unparsed() { Ast::class_tag = Ast::UNPARSED; }
  1217.     inline void mark_parsed()   { Ast::class_tag = Ast::NO_TAG; }
  1218.  
  1219.     AstClassBody(StoragePool *pool_) : pool(pool_),
  1220.                                        class_body_declarations(NULL),
  1221.                                        instance_variables(NULL),
  1222.                                        class_variables(NULL),
  1223.                                        methods(NULL),
  1224.                                        constructors(NULL),
  1225.                                        static_initializers(NULL),
  1226.                                        inner_classes(NULL),
  1227.                                        inner_interfaces(NULL),
  1228.                                        blocks(NULL),
  1229.                                        empty_declarations(NULL),
  1230.                                        default_constructor(NULL),
  1231.                                        this_block(NULL)
  1232.     {
  1233.         Ast::kind = Ast::CLASS_BODY;
  1234.         Ast::class_tag = Ast::NO_TAG;
  1235.         Ast::generated = 0;
  1236.     }
  1237.  
  1238.     virtual ~AstClassBody();
  1239.  
  1240.     inline Ast *&ClassBodyDeclaration(int i) { return (*class_body_declarations)[i]; }
  1241.     inline int NumClassBodyDeclarations() { return (class_body_declarations ? class_body_declarations -> Length() : 0); }
  1242.     inline void AllocateClassBodyDeclarations(int estimate = 0);
  1243.     inline void AddClassBodyDeclaration(Ast *);
  1244.     inline void AddClassBodyDeclarationNicely(Ast *);
  1245.  
  1246.     inline AstFieldDeclaration *&InstanceVariable(int i) { return (*instance_variables)[i]; }
  1247.     inline int NumInstanceVariables() { return (instance_variables ? instance_variables -> Length() : 0); }
  1248.     inline void AllocateInstanceVariables(int estimate = 0);
  1249.     inline void AddInstanceVariable(AstFieldDeclaration *);
  1250.  
  1251.     inline AstFieldDeclaration *&ClassVariable(int i) { return (*class_variables)[i]; }
  1252.     inline int NumClassVariables() { return (class_variables ? class_variables -> Length() : 0); }
  1253.     inline void AllocateClassVariables(int estimate = 0);
  1254.     inline void AddClassVariable(AstFieldDeclaration *);
  1255.  
  1256.     inline AstMethodDeclaration *&Method(int i) { return (*methods)[i]; }
  1257.     inline int NumMethods() { return (methods ? methods -> Length() : 0); }
  1258.     inline void AllocateMethods(int estimate = 0);
  1259.     inline void AddMethod(AstMethodDeclaration *);
  1260.  
  1261.     inline AstConstructorDeclaration *&Constructor(int i) { return (*constructors)[i]; }
  1262.     inline int NumConstructors() { return (constructors ? constructors -> Length() : 0); }
  1263.     inline void AllocateConstructors(int estimate = 0);
  1264.     inline void AddConstructor(AstConstructorDeclaration *);
  1265.  
  1266.     inline AstStaticInitializer *&StaticInitializer(int i) { return (*static_initializers)[i]; }
  1267.     inline int NumStaticInitializers() { return (static_initializers ? static_initializers -> Length() : 0); }
  1268.     inline void AllocateStaticInitializers(int estimate = 0);
  1269.     inline void AddStaticInitializer(AstStaticInitializer *);
  1270.  
  1271.     inline AstClassDeclaration *&NestedClass(int i) { return (*inner_classes)[i]; }
  1272.     inline int NumNestedClasses() { return (inner_classes ? inner_classes -> Length() : 0); }
  1273.     inline void AllocateNestedClasses(int estimate = 0);
  1274.     inline void AddNestedClass(AstClassDeclaration *);
  1275.  
  1276.     inline AstInterfaceDeclaration *&NestedInterface(int i) { return (*inner_interfaces)[i]; }
  1277.     inline int NumNestedInterfaces() { return (inner_interfaces ? inner_interfaces -> Length() : 0); }
  1278.     inline void AllocateNestedInterfaces(int estimate = 0);
  1279.     inline void AddNestedInterface(AstInterfaceDeclaration *);
  1280.  
  1281.     inline AstBlock *&Block(int i) { return (*blocks)[i]; }
  1282.     inline int NumBlocks() { return (blocks ? blocks -> Length() : 0); }
  1283.     inline void AllocateBlocks(int estimate = 0);
  1284.     inline void AddBlock(AstBlock *);
  1285.  
  1286.     inline AstEmptyDeclaration *&EmptyDeclaration(int i) { return (*empty_declarations)[i]; }
  1287.     inline int NumEmptyDeclarations() { return (empty_declarations ? empty_declarations -> Length() : 0); }
  1288.     inline void AllocateEmptyDeclarations(int estimate = 0);
  1289.     inline void AddEmptyDeclaration(AstEmptyDeclaration *);
  1290.  
  1291. #ifdef TEST
  1292.     virtual void Print(LexStream &);
  1293.     virtual void Unparse(Ostream &, LexStream &);
  1294. #endif
  1295.  
  1296.     virtual Ast *Clone(StoragePool *);
  1297.  
  1298.     virtual LexStream::TokenIndex LeftToken() { return left_brace_token; }
  1299.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  1300. };
  1301.  
  1302.  
  1303.  
  1304. //
  1305. // TypeDeclaration --> ClassDeclaration
  1306. //                   | InterfaceDeclaration
  1307. //                   | EmptyDeclaration
  1308. //
  1309. // ClassDeclaration --> <CLASS, ClassModifiers, class_token, identifier_token, Super_opt, Interfaces, ClassBody>
  1310. //
  1311. // Super --> Name
  1312. //
  1313. // Interface --> Name
  1314. //
  1315. // ClassModifier --> Modifier  (ABSTRACT, FINAL or PUBLIC)
  1316. //
  1317. // ClassBodyDeclaration --> FieldDeclaration
  1318. //                        | MethodDeclaration
  1319. //                        | ConstructorDeclaration
  1320. //                        | StaticInitializer
  1321. //
  1322. class AstClassDeclaration : public AstStatement
  1323. {
  1324.     AstArray<AstModifier *> *class_modifiers;
  1325.     AstArray<AstExpression *> *interfaces;
  1326.  
  1327. public:
  1328.     SemanticEnvironment *semantic_environment;
  1329.  
  1330.     LexStream::TokenIndex class_token;
  1331.     LexStream::TokenIndex identifier_token;
  1332.     Ast *super_opt;
  1333.     AstClassBody *class_body;
  1334.  
  1335.     AstClassDeclaration(StoragePool *pool_) : class_modifiers(NULL),
  1336.                                               interfaces(NULL),
  1337.                                               semantic_environment(NULL)
  1338.     {
  1339.         Ast::kind = Ast::CLASS;
  1340.         Ast::class_tag = Ast::NO_TAG;
  1341.         Ast::generated = 0;
  1342.     AstStatement::pool = pool_;
  1343.     }
  1344.  
  1345.     virtual ~AstClassDeclaration();
  1346.  
  1347.     bool IsValid() { return semantic_environment != NULL; }
  1348.  
  1349.     inline void MarkLocal()
  1350.     {
  1351.         Ast::class_tag = Ast::STATEMENT;
  1352.         AstStatement::is_reachable = true;
  1353.         AstStatement::can_complete_normally = true;
  1354.         AstStatement::defined_variables = NULL;
  1355.     }
  1356.  
  1357.     inline AstModifier *&ClassModifier(int i) { return (*class_modifiers)[i]; }
  1358.     inline int NumClassModifiers() { return (class_modifiers ? class_modifiers -> Length() : 0); }
  1359.     inline void AllocateClassModifiers(int estimate = 0);
  1360.     inline void AddClassModifier(AstModifier *);
  1361.  
  1362.     inline AstExpression *&Interface(int i) { return (*interfaces)[i]; }
  1363.     inline int NumInterfaces() { return (interfaces ? interfaces -> Length() : 0); }
  1364.     inline void AllocateInterfaces(int estimate = 0);
  1365.     inline void AddInterface(AstExpression *);
  1366.  
  1367. #ifdef TEST
  1368.     virtual void Print(LexStream &);
  1369.     virtual void Unparse(Ostream &, LexStream &);
  1370. #endif
  1371.  
  1372.     virtual Ast *Clone(StoragePool *);
  1373.  
  1374.     virtual LexStream::TokenIndex LeftToken()
  1375.     {
  1376.         return (NumClassModifiers() > 0 ? (*class_modifiers)[0] -> LeftToken() : class_token);
  1377.     }
  1378.     virtual LexStream::TokenIndex RightToken() { return class_body -> RightToken(); }
  1379. };
  1380.  
  1381.  
  1382. //
  1383. // VariableInitializer --> Expression
  1384. //                       | ArrayInitializer
  1385. //
  1386. // ArrayInitializer --> <ARRAY_INITIALIZER, {_token, VariableInitializers, }_token>
  1387. //
  1388. class AstArrayInitializer : public Ast
  1389. {
  1390. private:
  1391.  
  1392.     StoragePool *pool;
  1393.     AstArray<Ast *> *variable_initializers;
  1394.  
  1395. public:
  1396.     LexStream::TokenIndex left_brace_token;
  1397.     LexStream::TokenIndex right_brace_token;
  1398.  
  1399.     AstArrayInitializer(StoragePool *pool_) : pool(pool_),
  1400.                                               variable_initializers(NULL)
  1401.     {
  1402.         Ast::kind = Ast::ARRAY_INITIALIZER;
  1403.         Ast::class_tag = Ast::NO_TAG;
  1404.         Ast::generated = 0;
  1405.     }
  1406.  
  1407.     virtual ~AstArrayInitializer();
  1408.  
  1409.     inline Ast *&VariableInitializer(int i) { return (*variable_initializers)[i]; }
  1410.     inline int NumVariableInitializers() { return (variable_initializers ? variable_initializers -> Length() : 0); }
  1411.     inline void AllocateVariableInitializers(int estimate = 0);
  1412.     inline void AddVariableInitializer(Ast *);
  1413.  
  1414. #ifdef TEST
  1415.     virtual void Print(LexStream &);
  1416.     virtual void Unparse(Ostream &, LexStream &);
  1417. #endif
  1418.  
  1419.     virtual Ast *Clone(StoragePool *);
  1420.  
  1421.     virtual LexStream::TokenIndex LeftToken() { return left_brace_token; }
  1422.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  1423. };
  1424.  
  1425.  
  1426. //
  1427. // VariableDeclaratorId --> <VARIABLE_DECLARATOR_NAME, identifier_token, Brackets>
  1428. //
  1429. class AstVariableDeclaratorId : public Ast
  1430. {
  1431. private:
  1432.  
  1433.     StoragePool *pool;
  1434.     AstArray<AstBrackets *> *brackets;
  1435.  
  1436. public:
  1437.  
  1438.     LexStream::TokenIndex identifier_token;
  1439.  
  1440.     AstVariableDeclaratorId(StoragePool *pool_) : pool(pool_),
  1441.                                                   brackets(NULL)
  1442.     {
  1443.         Ast::kind = Ast::VARIABLE_DECLARATOR_NAME;
  1444.         Ast::class_tag = Ast::NO_TAG;
  1445.         Ast::generated = 0;
  1446.     }
  1447.  
  1448.     virtual ~AstVariableDeclaratorId();
  1449.  
  1450.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  1451.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  1452.     inline void AllocateBrackets(int estimate = 0);
  1453.     inline void AddBrackets(AstBrackets *);
  1454.  
  1455. #ifdef TEST
  1456.     virtual void Print(LexStream &);
  1457.     virtual void Unparse(Ostream &, LexStream &);
  1458. #endif
  1459.  
  1460.     virtual Ast *Clone(StoragePool *);
  1461.  
  1462.     virtual LexStream::TokenIndex LeftToken()  { return identifier_token; }
  1463.     virtual LexStream::TokenIndex RightToken()
  1464.     {
  1465.         return (NumBrackets() > 0 ? (*brackets)[NumBrackets() - 1] -> RightToken() : identifier_token);
  1466.     }
  1467. };
  1468.  
  1469.  
  1470. //
  1471. // VariableDeclarator --> <VARIABLE_DECLARATOR, VariableDeclaratorId, VariableInitializer_opt>
  1472. //
  1473. class AstVariableDeclarator : public Ast
  1474. {
  1475. public:
  1476.     VariableSymbol *symbol;
  1477.     bool pending; // when true, this variable signals that the variable_initializer_opt for this variable is currently being evaluated
  1478.  
  1479.     AstVariableDeclaratorId *variable_declarator_name;
  1480.     Ast *variable_initializer_opt;
  1481.  
  1482.     AstVariableDeclarator() : symbol(NULL),
  1483.                               pending(false)
  1484.     {
  1485.         Ast::kind = Ast::VARIABLE_DECLARATOR;
  1486.         Ast::class_tag = Ast::NO_TAG;
  1487.         Ast::generated = 0;
  1488.     }
  1489.  
  1490.     virtual ~AstVariableDeclarator();
  1491.  
  1492. #ifdef TEST
  1493.     virtual void Print(LexStream &);
  1494.     virtual void Unparse(Ostream &, LexStream &);
  1495. #endif
  1496.  
  1497.     virtual Ast *Clone(StoragePool *);
  1498.  
  1499.     virtual LexStream::TokenIndex LeftToken() { return variable_declarator_name -> LeftToken(); }
  1500.  
  1501.     virtual LexStream::TokenIndex RightToken()
  1502.     {
  1503.         return (variable_initializer_opt ?
  1504.                 variable_initializer_opt -> RightToken() :
  1505.                 variable_declarator_name -> RightToken());
  1506.     }
  1507. };
  1508.  
  1509.  
  1510. //
  1511. // FieldDeclaration --> <FIELD, VariableModifiers, Type, VariableDeclarators, ;_token>
  1512. //
  1513. // FieldModifier --> Modifier (PUBLIC, PROTECTED, PRIVATE, FINAL, STATIC, TRANSIENT or VOLATILE)
  1514. //
  1515. class AstFieldDeclaration : public Ast
  1516. {
  1517.     StoragePool *pool;
  1518.     AstArray<AstModifier *> *variable_modifiers;
  1519.     AstArray<AstVariableDeclarator *> *variable_declarators;
  1520.  
  1521. public:
  1522.  
  1523.     Ast *type;
  1524.     LexStream::TokenIndex semicolon_token;
  1525.  
  1526.     AstFieldDeclaration(StoragePool *pool_) : pool(pool_),
  1527.                                               variable_modifiers(NULL),
  1528.                                               variable_declarators(NULL)
  1529.     {
  1530.         Ast::kind = Ast::FIELD;
  1531.         Ast::class_tag = Ast::NO_TAG;
  1532.         Ast::generated = 0;
  1533.     }
  1534.  
  1535.     virtual ~AstFieldDeclaration();
  1536.  
  1537.     inline void MarkStatic() { Ast::class_tag = Ast::STATIC_FIELD; }
  1538.  
  1539.     inline AstModifier *&VariableModifier(int i) { return (*variable_modifiers)[i]; }
  1540.     inline int NumVariableModifiers() { return (variable_modifiers ? variable_modifiers -> Length() : 0); }
  1541.     inline void AllocateVariableModifiers(int estimate = 0);
  1542.     inline void AddVariableModifier(AstModifier *);
  1543.  
  1544.     inline AstVariableDeclarator *&VariableDeclarator(int i) { return (*variable_declarators)[i]; }
  1545.     inline int NumVariableDeclarators() { return (variable_declarators ? variable_declarators -> Length() : 0); }
  1546.     inline void AllocateVariableDeclarators(int estimate = 0);
  1547.     inline void AddVariableDeclarator(AstVariableDeclarator *);
  1548.  
  1549. #ifdef TEST
  1550.     virtual void Print(LexStream &);
  1551.     virtual void Unparse(Ostream &, LexStream &);
  1552. #endif
  1553.  
  1554.     virtual Ast *Clone(StoragePool *);
  1555.  
  1556.     virtual LexStream::TokenIndex LeftToken()
  1557.     {
  1558.         return (NumVariableModifiers() > 0 ? (*variable_modifiers)[0] -> LeftToken() : type -> LeftToken());
  1559.     }
  1560.  
  1561.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1562. };
  1563.  
  1564.  
  1565. //
  1566. // FormalParameter --> <PARAMETER, Type, VariableDeclaratorId>
  1567. //
  1568. class AstFormalParameter : public Ast
  1569. {
  1570.     StoragePool *pool;
  1571.     AstArray<AstModifier *> *parameter_modifiers;
  1572.  
  1573. public:
  1574.  
  1575.     Ast *type;
  1576.     AstVariableDeclarator *formal_declarator;
  1577.  
  1578.     AstFormalParameter(StoragePool *pool_) : pool(pool_),
  1579.                                              parameter_modifiers(NULL)
  1580.     {
  1581.         Ast::kind = Ast::PARAMETER;
  1582.         Ast::class_tag = Ast::NO_TAG;
  1583.         Ast::generated = 0;
  1584.     }
  1585.  
  1586.     virtual ~AstFormalParameter();
  1587.  
  1588.     inline AstModifier *&ParameterModifier(int i) { return (*parameter_modifiers)[i]; }
  1589.     inline int NumParameterModifiers() { return (parameter_modifiers ? parameter_modifiers -> Length() : 0); }
  1590.     inline void AllocateParameterModifiers(int estimate = 0);
  1591.     inline void AddParameterModifier(AstModifier *);
  1592.  
  1593. #ifdef TEST
  1594.     virtual void Print(LexStream &);
  1595.     virtual void Unparse(Ostream &, LexStream &);
  1596. #endif
  1597.  
  1598.     virtual Ast *Clone(StoragePool *);
  1599.  
  1600.     virtual LexStream::TokenIndex LeftToken()
  1601.     {
  1602.        return (NumParameterModifiers() > 0 ? (*parameter_modifiers)[0] -> LeftToken() : type -> LeftToken());
  1603.     }
  1604.     virtual LexStream::TokenIndex RightToken() { return formal_declarator -> RightToken(); }
  1605. };
  1606.  
  1607.  
  1608. //
  1609. // MethodDeclarator --> <METHOD_DECLARATOR, identifier_token, (_token, FormalParameters, )_token, Brackets>
  1610. //
  1611. class AstMethodDeclarator : public Ast
  1612. {
  1613. private:
  1614.  
  1615.     StoragePool *pool;
  1616.     AstArray<AstBrackets *> *brackets;
  1617.     AstArray<AstFormalParameter *> *formal_parameters;
  1618.  
  1619. public:
  1620.     LexStream::TokenIndex identifier_token;
  1621.     LexStream::TokenIndex left_parenthesis_token;
  1622.     LexStream::TokenIndex right_parenthesis_token;
  1623.  
  1624.     AstMethodDeclarator(StoragePool *pool_) : pool(pool_),
  1625.                                               brackets(NULL),
  1626.                                               formal_parameters(NULL)
  1627.     {
  1628.         Ast::kind = Ast::METHOD_DECLARATOR;
  1629.         Ast::class_tag = Ast::NO_TAG;
  1630.         Ast::generated = 0;
  1631.     }
  1632.  
  1633.     virtual ~AstMethodDeclarator();
  1634.  
  1635.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  1636.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  1637.     inline void AllocateBrackets(int estimate = 0);
  1638.     inline void AddBrackets(AstBrackets *);
  1639.  
  1640.     inline AstFormalParameter *&FormalParameter(int i) { return (*formal_parameters)[i]; }
  1641.     inline int NumFormalParameters() { return (formal_parameters ? formal_parameters -> Length() : 0); }
  1642.     inline void AllocateFormalParameters(int estimate = 0);
  1643.     inline void AddFormalParameter(AstFormalParameter *);
  1644.  
  1645. #ifdef TEST
  1646.     virtual void Print(LexStream &);
  1647.     virtual void Unparse(Ostream &, LexStream &);
  1648. #endif
  1649.  
  1650.     virtual Ast *Clone(StoragePool *);
  1651.  
  1652.     virtual LexStream::TokenIndex LeftToken() { return identifier_token; }
  1653.  
  1654.     virtual LexStream::TokenIndex RightToken()
  1655.     {
  1656.         return (NumBrackets() ? Brackets(NumBrackets() - 1) -> RightToken() : right_parenthesis_token);
  1657.     }
  1658. };
  1659.  
  1660.  
  1661. //
  1662. // MethodDeclaration --> <METHOD, MethodModifiers, Type, MethodDeclarator, Throws, MethodBody>
  1663. //
  1664. // MethodModifier --> Modifier (PUBLIC, PROTECTED, PRIVATE, STATIC, ABSTRACT, FINAL, NATIVE or SYNCHRONIZED)
  1665. //
  1666. // Throws --> Names
  1667. //
  1668. // MethodBody --> Block
  1669. //              | EmptyStatement
  1670. //
  1671. class AstMethodDeclaration : public Ast
  1672. {
  1673.     StoragePool *pool;
  1674.     AstArray<AstModifier *> *method_modifiers;
  1675.     AstArray<AstExpression *> *throws;
  1676.  
  1677. public:
  1678.     MethodSymbol *method_symbol;
  1679.  
  1680.     Ast *type;
  1681.     AstMethodDeclarator *method_declarator;
  1682.     AstStatement *method_body;
  1683.  
  1684.     AstMethodDeclaration(StoragePool *pool_) : pool(pool_),
  1685.                                                method_modifiers(NULL),
  1686.                                                throws(NULL),
  1687.                                                method_symbol(NULL)
  1688.     {
  1689.         Ast::kind = Ast::METHOD;
  1690.         Ast::class_tag = Ast::NO_TAG;
  1691.         Ast::generated = 0;
  1692.     }
  1693.  
  1694.     virtual ~AstMethodDeclaration();
  1695.  
  1696.     bool IsValid() { return method_symbol != NULL; }
  1697.  
  1698.     bool IsSignature() { return (method_body -> EmptyStatementCast() != NULL); }
  1699.  
  1700.     inline AstModifier *&MethodModifier(int i) { return (*method_modifiers)[i]; }
  1701.     inline int NumMethodModifiers() { return (method_modifiers ? method_modifiers -> Length() : 0); }
  1702.     inline void AllocateMethodModifiers(int estimate = 0);
  1703.     inline void AddMethodModifier(AstModifier *);
  1704.  
  1705.     inline AstExpression *&Throw(int i) { return (*throws)[i]; }
  1706.     inline int NumThrows() { return (throws ? throws -> Length() : 0); }
  1707.     inline void AllocateThrows(int estimate = 0);
  1708.     inline void AddThrow(AstExpression *);
  1709.  
  1710. #ifdef TEST
  1711.     virtual void Print(LexStream &);
  1712.     virtual void Unparse(Ostream &, LexStream &);
  1713. #endif
  1714.  
  1715.     virtual Ast *Clone(StoragePool *);
  1716.  
  1717.     virtual LexStream::TokenIndex LeftToken()
  1718.     {
  1719.         return (NumMethodModifiers() > 0 ? (*method_modifiers)[0] -> LeftToken() : type -> LeftToken());
  1720.     }
  1721.     virtual LexStream::TokenIndex RightToken() { return method_body -> RightToken(); }
  1722. };
  1723.  
  1724. //
  1725. // StaticInitializer --> <STATIC_INITIALIZER, static_token, Block>
  1726. //
  1727. class AstStaticInitializer : public Ast
  1728. {
  1729. public:
  1730.     LexStream::TokenIndex static_token;
  1731.     AstBlock *block;
  1732.  
  1733.     AstStaticInitializer()
  1734.     {
  1735.         Ast::kind = Ast::STATIC_INITIALIZER;
  1736.         Ast::class_tag = Ast::NO_TAG;
  1737.         Ast::generated = 0;
  1738.     }
  1739.  
  1740.     virtual ~AstStaticInitializer();
  1741.  
  1742. #ifdef TEST
  1743.     virtual void Print(LexStream &);
  1744.     virtual void Unparse(Ostream &, LexStream &);
  1745. #endif
  1746.  
  1747.     virtual Ast *Clone(StoragePool *);
  1748.  
  1749.     virtual LexStream::TokenIndex LeftToken() { return static_token; }
  1750.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  1751. };
  1752.  
  1753.  
  1754. //
  1755. // ThisCall --> <THIS_CALL, this_token, (_token, Arguments, )_token, ;_token>
  1756. //
  1757. // Argument --> Expression
  1758. //
  1759. class AstThisCall : public AstStatement
  1760. {
  1761. private:
  1762.  
  1763.     AstArray<AstExpression *> *arguments;
  1764.     AstArray<AstExpression *> *local_arguments_opt; // used only for local classes that use enclosed local variables
  1765.  
  1766. public:
  1767.     MethodSymbol *symbol;
  1768.  
  1769.     AstExpression *base_opt;
  1770.     LexStream::TokenIndex dot_token_opt;
  1771.     LexStream::TokenIndex this_token;
  1772.     LexStream::TokenIndex left_parenthesis_token;
  1773.     LexStream::TokenIndex right_parenthesis_token;
  1774.     LexStream::TokenIndex semicolon_token;
  1775.  
  1776.     AstThisCall(StoragePool *pool_) : arguments(NULL),
  1777.                                       local_arguments_opt(NULL),
  1778.                                       symbol(NULL)
  1779.     {
  1780.         Ast::kind = Ast::THIS_CALL;
  1781.         Ast::class_tag = Ast::STATEMENT;
  1782.         Ast::generated = 0;
  1783.         AstStatement::pool = pool_;
  1784.         AstStatement::is_reachable = false;
  1785.         AstStatement::can_complete_normally = false;
  1786.         AstStatement::defined_variables = NULL;
  1787.     }
  1788.  
  1789.     virtual ~AstThisCall();
  1790.  
  1791.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  1792.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  1793.     inline void AllocateArguments(int estimate = 0);
  1794.     inline void AddArgument(AstExpression *);
  1795.  
  1796.     inline AstExpression *&LocalArgument(int i) { return (*local_arguments_opt)[i]; }
  1797.     inline int NumLocalArguments() { return (local_arguments_opt ? local_arguments_opt -> Length() : 0); }
  1798.     inline void AllocateLocalArguments(int estimate = 0);
  1799.     inline void AddLocalArgument(AstExpression *);
  1800.  
  1801. #ifdef TEST
  1802.     virtual void Print(LexStream &);
  1803.     virtual void Unparse(Ostream &, LexStream &);
  1804. #endif
  1805.  
  1806.     virtual Ast *Clone(StoragePool *);
  1807.  
  1808.     virtual LexStream::TokenIndex LeftToken() { return this_token; }
  1809.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1810. };
  1811.  
  1812.  
  1813. //
  1814. // SuperCall --> <SUPER_CALL, super_token, (_token, Arguments, )_token, ;_token>
  1815. //             | <SUPER_CALL, SuperField, (_token, Arguments, )_token, ;_token>
  1816. //
  1817. class AstSuperCall : public AstStatement
  1818. {
  1819. private:
  1820.  
  1821.     AstArray<AstExpression *> *arguments;
  1822.     AstArray<AstExpression *> *local_arguments_opt; // used only for local classes that use enclosed local variables
  1823.  
  1824.     bool add_null_argument;
  1825.  
  1826. public:
  1827.     MethodSymbol *symbol;
  1828.  
  1829.     AstExpression *base_opt;
  1830.     LexStream::TokenIndex dot_token_opt;
  1831.     LexStream::TokenIndex super_token;
  1832.     LexStream::TokenIndex left_parenthesis_token;
  1833.     LexStream::TokenIndex right_parenthesis_token;
  1834.     LexStream::TokenIndex semicolon_token;
  1835.  
  1836.     AstSuperCall(StoragePool *pool_) : arguments(NULL),
  1837.                                        local_arguments_opt(NULL),
  1838.                                        add_null_argument(false),
  1839.                                        symbol(NULL)
  1840.     {
  1841.         Ast::kind = Ast::SUPER_CALL;
  1842.         Ast::class_tag = Ast::STATEMENT;
  1843.         Ast::generated = 0;
  1844.         AstStatement::pool = pool_;
  1845.         AstStatement::is_reachable = false;
  1846.         AstStatement::can_complete_normally = false;
  1847.         AstStatement::defined_variables = NULL;
  1848.     }
  1849.  
  1850.     virtual ~AstSuperCall();
  1851.  
  1852.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  1853.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  1854.     inline void AllocateArguments(int estimate = 0);
  1855.     inline void AddArgument(AstExpression *);
  1856.  
  1857.     inline AstExpression *&LocalArgument(int i) { return (*local_arguments_opt)[i]; }
  1858.     inline int NumLocalArguments() { return (local_arguments_opt ? local_arguments_opt -> Length() : 0); }
  1859.     inline void AllocateLocalArguments(int estimate = 0);
  1860.     inline void AddLocalArgument(AstExpression *);
  1861.  
  1862.     inline void AddNullArgument() { add_null_argument = true; }
  1863.     inline bool NeedsExtraNullArgument() { return add_null_argument; }
  1864.  
  1865. #ifdef TEST
  1866.     virtual void Print(LexStream &);
  1867.     virtual void Unparse(Ostream &, LexStream &);
  1868. #endif
  1869.  
  1870.     virtual Ast *Clone(StoragePool *);
  1871.  
  1872.     virtual LexStream::TokenIndex LeftToken() { return (base_opt ? base_opt -> LeftToken() : super_token); }
  1873.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1874. };
  1875.  
  1876.  
  1877. //
  1878. // ConstructorDeclaration --> <CONSTRUCTOR, Constructormodifiers, MethodDeclarator, Throws, ConstructorBody>
  1879. //
  1880. // ConstructorBody --> <CONSTRUCTOR_BLOCK, {_token, ExplicitConstructorInvocation, BlockStatements, }_token>
  1881. //                   | MethodBody
  1882. //
  1883. // ConstructorModifier --> Modifier (PUBLIC, PROTECTED or PRIVATE)
  1884. //
  1885. // ExplicitConstructorInvocation --> ThisCall
  1886. //                                 | SuperCall
  1887. //
  1888. class AstConstructorBlock : public AstStatement
  1889. {
  1890. private:
  1891.  
  1892.     AstArray<AstStatement *> *local_init_statements;
  1893.  
  1894. public:
  1895.     BlockSymbol *block_symbol;
  1896.  
  1897.     LexStream::TokenIndex left_brace_token;
  1898.     Ast *explicit_constructor_invocation_opt;
  1899.     AstBlock *block;
  1900.     LexStream::TokenIndex right_brace_token;
  1901.  
  1902.     AstExpressionStatement *original_constructor_invocation;
  1903.  
  1904.     AstConstructorBlock(StoragePool *pool_) : local_init_statements(NULL),
  1905.                                               block_symbol(NULL),
  1906.                                               original_constructor_invocation(NULL)
  1907.     {
  1908.         Ast::kind = Ast::CONSTRUCTOR_BLOCK;
  1909.         Ast::class_tag = Ast::STATEMENT;
  1910.         Ast::generated = 0;
  1911.         AstStatement::pool = pool_;
  1912.         AstStatement::is_reachable = false;
  1913.         AstStatement::can_complete_normally = false;
  1914.         AstStatement::defined_variables = NULL;
  1915.     }
  1916.  
  1917.     virtual ~AstConstructorBlock();
  1918.  
  1919.     inline AstStatement *&LocalInitStatement(int i) { return (*local_init_statements)[i]; }
  1920.     inline int NumLocalInitStatements() { return (local_init_statements ? local_init_statements -> Length() : 0); }
  1921.     inline void AllocateLocalInitStatements(int estimate = 0);
  1922.     inline void AddLocalInitStatement(AstStatement *);
  1923.  
  1924. #ifdef TEST
  1925.     virtual void Print(LexStream &);
  1926.     virtual void Unparse(Ostream &, LexStream &);
  1927. #endif
  1928.  
  1929.     virtual Ast *Clone(StoragePool *);
  1930.  
  1931.     virtual LexStream::TokenIndex LeftToken()  { return left_brace_token;  }
  1932.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  1933. };
  1934.  
  1935.  
  1936. class AstConstructorDeclaration : public Ast
  1937. {
  1938.     StoragePool *pool;
  1939.     AstArray<AstModifier *> *constructor_modifiers;
  1940.     AstArray<AstExpression *> *throws;
  1941.  
  1942. public:
  1943.     MethodSymbol *constructor_symbol;
  1944.     int index;
  1945.  
  1946.     AstMethodDeclarator *constructor_declarator;
  1947.     AstConstructorBlock *constructor_body;
  1948.  
  1949.     AstConstructorDeclaration(StoragePool *pool_) : pool(pool_),
  1950.                                                     constructor_modifiers(NULL),
  1951.                                                     throws(NULL),
  1952.                                                     constructor_symbol(NULL),
  1953.                                                     index(CycleChecker::OMEGA)
  1954.     {
  1955.         Ast::kind = Ast::CONSTRUCTOR;
  1956.         Ast::class_tag = Ast::NO_TAG;
  1957.         Ast::generated = 0;
  1958.     }
  1959.  
  1960.     virtual ~AstConstructorDeclaration();
  1961.  
  1962.     bool IsValid() { return constructor_symbol != NULL; }
  1963.  
  1964.     inline AstModifier *&ConstructorModifier(int i) { return (*constructor_modifiers)[i]; }
  1965.     inline int NumConstructorModifiers() { return (constructor_modifiers ? constructor_modifiers -> Length() : 0); }
  1966.     inline void AllocateConstructorModifiers(int estimate = 0);
  1967.     inline void AddConstructorModifier(AstModifier *);
  1968.  
  1969.     inline AstExpression *&Throw(int i) { return (*throws)[i]; }
  1970.     inline int NumThrows() { return (throws ? throws -> Length() : 0); }
  1971.     inline void AllocateThrows(int estimate = 0);
  1972.     inline void AddThrow(AstExpression *);
  1973.  
  1974. #ifdef TEST
  1975.     virtual void Print(LexStream &);
  1976.     virtual void Unparse(Ostream &, LexStream &);
  1977. #endif
  1978.  
  1979.     virtual Ast *Clone(StoragePool *);
  1980.  
  1981.     virtual LexStream::TokenIndex LeftToken()
  1982.     {
  1983.         return (NumConstructorModifiers() > 0 ? (*constructor_modifiers)[0] -> LeftToken() : constructor_declarator -> LeftToken());
  1984.     }
  1985.     virtual LexStream::TokenIndex RightToken() { return constructor_body -> RightToken(); }
  1986. };
  1987.  
  1988.  
  1989. //
  1990. // InterfaceDeclaration --> <INTERFACE, Interfacemodifiers, interface_token, identifier_token, ExtendsInterfaces, {_token, InterfaceMemberDeclarations, }_token>
  1991. //
  1992. // InterfaceModifier --> Modifier (PUBLIC, ABSTRACT)
  1993. //
  1994. // ExtendsInterfaces --> Names
  1995. //
  1996. //
  1997. // InterfaceMemberDeclaration --> ConstantDeclaration
  1998. //                              | AbstractMethodDeclaration
  1999. //
  2000. // ConstantDeclaration --> FieldDeclaration (where the FieldModifierList is a Constantmodifiers)
  2001. //
  2002. // ConstantModifier --> Modifier (PUBLIC, STATIC or FINAL)
  2003. //
  2004. // AbstractMethodDeclaration --> MethodDeclaration (where MethodModifierList is a SignatureModifierList and the
  2005. //                                                  MethodBody is an EmptyStatement)
  2006. //
  2007. // SignatureModifier --> Modifier (PUBLIC or ABSTRACT)
  2008. //
  2009. class AstInterfaceDeclaration : public Ast
  2010. {
  2011. private:
  2012.     friend class Parser;
  2013.  
  2014.     StoragePool *pool;
  2015.     AstArray<AstModifier *> *interface_modifiers;
  2016.     AstArray<AstExpression *> *extends_interfaces;
  2017.     AstArray<Ast *> *interface_member_declarations;
  2018.  
  2019.     AstArray<AstFieldDeclaration *> *class_variables;
  2020.     AstArray<AstMethodDeclaration *> *methods;
  2021.     AstArray<AstClassDeclaration *> *inner_classes;
  2022.     AstArray<AstInterfaceDeclaration *> *inner_interfaces;
  2023.     AstArray<AstEmptyDeclaration *> *empty_declarations;
  2024.  
  2025. public:
  2026.  
  2027.     SemanticEnvironment *semantic_environment;
  2028.  
  2029.     LexStream::TokenIndex interface_token;
  2030.     LexStream::TokenIndex identifier_token;
  2031.     LexStream::TokenIndex left_brace_token;
  2032.     LexStream::TokenIndex right_brace_token;
  2033.  
  2034.     inline void mark_unparsed() { Ast::class_tag = Ast::UNPARSED; }
  2035.     inline void mark_parsed()   { Ast::class_tag = Ast::NO_TAG; }
  2036.  
  2037.     AstInterfaceDeclaration(StoragePool *pool_) : pool(pool_),
  2038.                                                   interface_modifiers(NULL),
  2039.                                                   extends_interfaces(NULL),
  2040.                                                   interface_member_declarations(NULL),
  2041.                                                   class_variables(NULL),
  2042.                                                   methods(NULL),
  2043.                                                   inner_classes(NULL),
  2044.                                                   inner_interfaces(NULL),
  2045.                                                   empty_declarations(NULL),
  2046.                                                   semantic_environment(NULL)
  2047.     {
  2048.         Ast::kind = Ast::INTERFACE;
  2049.         Ast::class_tag = Ast::NO_TAG;
  2050.         Ast::generated = 0;
  2051.     }
  2052.  
  2053.     virtual ~AstInterfaceDeclaration();
  2054.  
  2055.     bool IsValid() { return semantic_environment != NULL; }
  2056.  
  2057.     inline AstModifier *&InterfaceModifier(int i) { return (*interface_modifiers)[i]; }
  2058.     inline int NumInterfaceModifiers() { return (interface_modifiers ? interface_modifiers -> Length() : 0); }
  2059.     inline void AllocateInterfaceModifiers(int estimate = 0);
  2060.     inline void AddInterfaceModifier(AstModifier *);
  2061.  
  2062.     inline AstExpression *&ExtendsInterface(int i) { return (*extends_interfaces)[i]; }
  2063.     inline int NumExtendsInterfaces() { return (extends_interfaces ? extends_interfaces -> Length() : 0); }
  2064.     inline void AllocateExtendsInterfaces(int estimate = 0);
  2065.     inline void AddExtendsInterface(AstExpression *);
  2066.  
  2067.     inline Ast *&InterfaceMemberDeclaration(int i) { return (*interface_member_declarations)[i]; }
  2068.     inline int NumInterfaceMemberDeclarations()
  2069.                { return (interface_member_declarations ? interface_member_declarations -> Length() : 0); }
  2070.     inline void AllocateInterfaceMemberDeclarations(int estimate = 0);
  2071.     inline void AddInterfaceMemberDeclaration(Ast *);
  2072.  
  2073.     inline AstFieldDeclaration *&ClassVariable(int i) { return (*class_variables)[i]; }
  2074.     inline int NumClassVariables() { return (class_variables ? class_variables -> Length() : 0); }
  2075.     inline void AllocateClassVariables(int estimate = 0);
  2076.     inline void AddClassVariable(AstFieldDeclaration *);
  2077.  
  2078.     inline AstMethodDeclaration *&Method(int i) { return (*methods)[i]; }
  2079.     inline int NumMethods() { return (methods ? methods -> Length() : 0); }
  2080.     inline void AllocateMethods(int estimate = 0);
  2081.     inline void AddMethod(AstMethodDeclaration *);
  2082.  
  2083.     inline AstClassDeclaration *&NestedClass(int i) { return (*inner_classes)[i]; }
  2084.     inline int NumNestedClasses() { return (inner_classes ? inner_classes -> Length() : 0); }
  2085.     inline void AllocateNestedClasses(int estimate = 0);
  2086.     inline void AddNestedClass(AstClassDeclaration *);
  2087.  
  2088.     inline AstInterfaceDeclaration *&NestedInterface(int i) { return (*inner_interfaces)[i]; }
  2089.     inline int NumNestedInterfaces() { return (inner_interfaces ? inner_interfaces -> Length() : 0); }
  2090.     inline void AllocateNestedInterfaces(int estimate = 0);
  2091.     inline void AddNestedInterface(AstInterfaceDeclaration *);
  2092.  
  2093.     inline AstEmptyDeclaration *&EmptyDeclaration(int i) { return (*empty_declarations)[i]; }
  2094.     inline int NumEmptyDeclarations() { return (empty_declarations ? empty_declarations -> Length() : 0); }
  2095.     inline void AllocateEmptyDeclarations(int estimate = 0);
  2096.     inline void AddEmptyDeclaration(AstEmptyDeclaration *);
  2097.  
  2098. #ifdef TEST
  2099.     virtual void Print(LexStream &);
  2100.     virtual void Unparse(Ostream &, LexStream &);
  2101. #endif
  2102.  
  2103.     virtual Ast *Clone(StoragePool *);
  2104.  
  2105.     virtual LexStream::TokenIndex LeftToken()
  2106.     {
  2107.         return (NumInterfaceModifiers() > 0 ? (*interface_modifiers)[0] -> LeftToken() : interface_token);
  2108.     }
  2109.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  2110. };
  2111.  
  2112.  
  2113. //
  2114. // LocalVariableDeclarationStatement --> <LOCAL_VARIABLE_DECLARATION, Type, VariableDeclarators, ;_token_opt>
  2115. //
  2116. class AstLocalVariableDeclarationStatement : public AstStatement
  2117. {
  2118.     AstArray<AstModifier *> *local_modifiers;
  2119.     AstArray<AstVariableDeclarator *> *variable_declarators;
  2120.  
  2121. public:
  2122.     Ast *type;
  2123.     LexStream::TokenIndex semicolon_token_opt;
  2124.  
  2125.     AstLocalVariableDeclarationStatement(StoragePool *pool_) : local_modifiers(NULL),
  2126.                                                                variable_declarators(NULL)
  2127.     {
  2128.         Ast::kind = Ast::LOCAL_VARIABLE_DECLARATION;
  2129.         Ast::class_tag = Ast::STATEMENT;
  2130.         Ast::generated = 0;
  2131.         AstStatement::pool = pool_;
  2132.         AstStatement::is_reachable = false;
  2133.         AstStatement::can_complete_normally = false;
  2134.         AstStatement::defined_variables = NULL;
  2135.     }
  2136.  
  2137.     virtual ~AstLocalVariableDeclarationStatement();
  2138.  
  2139.     inline AstModifier *&LocalModifier(int i) { return (*local_modifiers)[i]; }
  2140.     inline int NumLocalModifiers() { return (local_modifiers ? local_modifiers -> Length() : 0); }
  2141.     inline void AllocateLocalModifiers(int estimate = 0);
  2142.     inline void AddLocalModifier(AstModifier *);
  2143.  
  2144.     inline AstVariableDeclarator *&VariableDeclarator(int i) { return (*variable_declarators)[i]; }
  2145.     inline int NumVariableDeclarators() { return (variable_declarators ? variable_declarators -> Length() : 0); }
  2146.     inline void AllocateVariableDeclarators(int estimate = 0);
  2147.     inline void AddVariableDeclarator(AstVariableDeclarator *);
  2148.  
  2149. #ifdef TEST
  2150.     virtual void Print(LexStream &);
  2151.     virtual void Unparse(Ostream &, LexStream &);
  2152. #endif
  2153.  
  2154.     virtual Ast *Clone(StoragePool *);
  2155.  
  2156.     virtual LexStream::TokenIndex LeftToken()
  2157.     {
  2158.         return (NumLocalModifiers() > 0 ? (*local_modifiers)[0] -> LeftToken() : type -> LeftToken());
  2159.     }
  2160.     virtual LexStream::TokenIndex RightToken()
  2161.     {
  2162.         return (semicolon_token_opt ? semicolon_token_opt : VariableDeclarator(NumVariableDeclarators() - 1) -> RightToken());
  2163.     }
  2164. };
  2165.  
  2166. //
  2167. // Statement --> IfStatement
  2168. //             | WhileStatement
  2169. //             | ForStatement
  2170. //             | Block
  2171. //             | EmptyStatement
  2172. //             | ExpressionStatement
  2173. //             | SwitchStatement
  2174. //             | DoStatement
  2175. //             | BreakStatement
  2176. //             | ContinueStatement
  2177. //             | ReturnStatement
  2178. //             | SynchronizedStatement
  2179. //             | ThrowStatement
  2180. //             | TryStatement
  2181. //
  2182. // Label --> identifier_token
  2183. //
  2184. // IfStatement --> <IF, Label_opt, if_token, Expression, TrueStatement, FalseStatement_opt>
  2185. //
  2186. // TrueStatement --> Statement
  2187. //
  2188. // FalseStatement --> Statement
  2189. //
  2190. class AstIfStatement : public AstStatement
  2191. {
  2192. public:
  2193.     LexStream::TokenIndex if_token;
  2194.     AstExpression *expression;
  2195.     AstStatement *true_statement;
  2196.     AstStatement *false_statement_opt;
  2197.  
  2198.     AstIfStatement(StoragePool *pool_) : expression(NULL)
  2199.     {
  2200.         Ast::kind = Ast::IF;
  2201.         Ast::class_tag = Ast::STATEMENT;
  2202.         Ast::generated = 0;
  2203.         AstStatement::pool = pool_;
  2204.         AstStatement::is_reachable = false;
  2205.         AstStatement::can_complete_normally = false;
  2206.         AstStatement::defined_variables = NULL;
  2207.     }
  2208.  
  2209.     virtual ~AstIfStatement();
  2210.  
  2211. #ifdef TEST
  2212.     virtual void Print(LexStream &);
  2213.     virtual void Unparse(Ostream &, LexStream &);
  2214. #endif
  2215.  
  2216.     virtual Ast *Clone(StoragePool *);
  2217.  
  2218.     virtual LexStream::TokenIndex LeftToken()
  2219.     {
  2220.         return if_token;
  2221.     }
  2222.     virtual LexStream::TokenIndex RightToken()
  2223.     {
  2224.         return (false_statement_opt ? false_statement_opt -> RightToken()
  2225.                                     : true_statement -> RightToken());
  2226.     }
  2227. };
  2228.  
  2229.  
  2230. //
  2231. // EmptyStatement --> <EMPTY_STATEMENT, Label_opt, ;_token>
  2232. //
  2233. class AstEmptyStatement : public AstStatement
  2234. {
  2235. public:
  2236.     LexStream::TokenIndex semicolon_token;
  2237.  
  2238.     AstEmptyStatement(StoragePool *pool_, LexStream::TokenIndex token_) : semicolon_token(token_)
  2239.     {
  2240.         Ast::kind = Ast::EMPTY_STATEMENT;
  2241.         Ast::class_tag = Ast::STATEMENT;
  2242.         Ast::generated = 0;
  2243.         AstStatement::pool = pool_;
  2244.         AstStatement::is_reachable = false;
  2245.         AstStatement::can_complete_normally = false;
  2246.         AstStatement::defined_variables = NULL;
  2247.     }
  2248.  
  2249.     virtual ~AstEmptyStatement();
  2250.  
  2251. #ifdef TEST
  2252.     virtual void Print(LexStream &);
  2253.     virtual void Unparse(Ostream &, LexStream &);
  2254. #endif
  2255.  
  2256.     virtual Ast *Clone(StoragePool *);
  2257.  
  2258.     virtual LexStream::TokenIndex LeftToken()
  2259.     {
  2260.         return semicolon_token;
  2261.     }
  2262.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2263. };
  2264.  
  2265.  
  2266. //
  2267. // ExpressionStatement --> <EXPRESSION_STATEMENT, Label_opt, Expression, ;_token_opt>
  2268. //
  2269. class AstExpressionStatement : public AstStatement
  2270. {
  2271. public:
  2272.     AstExpression *expression;
  2273.     LexStream::TokenIndex semicolon_token_opt;
  2274.  
  2275.     AstExpressionStatement(StoragePool *pool_)
  2276.     {
  2277.         Ast::kind = Ast::EXPRESSION_STATEMENT;
  2278.         Ast::class_tag = Ast::STATEMENT;
  2279.         Ast::generated = 0;
  2280.         AstStatement::pool = pool_;
  2281.         AstStatement::is_reachable = false;
  2282.         AstStatement::can_complete_normally = false;
  2283.         AstStatement::defined_variables = NULL;
  2284.     }
  2285.  
  2286.     virtual ~AstExpressionStatement();
  2287.  
  2288. #ifdef TEST
  2289.     virtual void Print(LexStream &);
  2290.     virtual void Unparse(Ostream &, LexStream &);
  2291. #endif
  2292.  
  2293.     virtual Ast *Clone(StoragePool *);
  2294.  
  2295.     virtual LexStream::TokenIndex LeftToken()
  2296.     {
  2297.         return expression -> LeftToken();
  2298.     }
  2299.     virtual LexStream::TokenIndex RightToken()
  2300.     {
  2301.         return (semicolon_token_opt ? semicolon_token_opt : expression -> RightToken());
  2302.     }
  2303. };
  2304.  
  2305.  
  2306. //
  2307. // SwitchLabel --> CaseLabel
  2308. //               | DefaultLabel
  2309. //
  2310. // CaseLabel --> <CASE, case_token, Expression, :_token>
  2311. //
  2312. class AstCaseLabel : public Ast
  2313. {
  2314. public:
  2315.     LexStream::TokenIndex case_token;
  2316.     AstExpression *expression;
  2317.     LexStream::TokenIndex colon_token;
  2318.     int map_index;
  2319.  
  2320.     AstCaseLabel()
  2321.     {
  2322.         Ast::kind = Ast::CASE;
  2323.         Ast::class_tag = Ast::NO_TAG;
  2324.         Ast::generated = 0;
  2325.     }
  2326.  
  2327.     virtual ~AstCaseLabel();
  2328.  
  2329. #ifdef TEST
  2330.     virtual void Print(LexStream &);
  2331.     virtual void Unparse(Ostream &, LexStream &);
  2332. #endif
  2333.  
  2334.     virtual Ast *Clone(StoragePool *);
  2335.  
  2336.     virtual LexStream::TokenIndex LeftToken() { return case_token; }
  2337.     virtual LexStream::TokenIndex RightToken() { return colon_token; }
  2338. };
  2339.  
  2340.  
  2341. //
  2342. // DefaultLabel --> <DEFAULT, default_token, :_token>
  2343. //
  2344. class AstDefaultLabel : public Ast
  2345. {
  2346. public:
  2347.     LexStream::TokenIndex default_token;
  2348.     LexStream::TokenIndex colon_token;
  2349.  
  2350.     AstDefaultLabel()
  2351.     {
  2352.         Ast::kind = Ast::DEFAULT;
  2353.         Ast::class_tag = Ast::NO_TAG;
  2354.         Ast::generated = 0;
  2355.     }
  2356.  
  2357.     virtual ~AstDefaultLabel();
  2358.  
  2359. #ifdef TEST
  2360.     virtual void Print(LexStream &);
  2361.     virtual void Unparse(Ostream &, LexStream &);
  2362. #endif
  2363.  
  2364.     virtual Ast *Clone(StoragePool *);
  2365.  
  2366.     virtual LexStream::TokenIndex LeftToken() { return default_token; }
  2367.     virtual LexStream::TokenIndex RightToken() { return colon_token; }
  2368. };
  2369.  
  2370.  
  2371. //
  2372. // SwitchBlockStatement --> <SWITCH_BLOCK, SwitchLabels, BlockStatements>
  2373. //
  2374. class AstSwitchBlockStatement : public Ast
  2375. {
  2376. private:
  2377.     StoragePool *pool;
  2378.  
  2379.     AstArray<AstStatement *> *block_statements;
  2380.     AstArray<Ast *> *switch_labels;
  2381.     VariableSymbolArray *locally_defined_variables;
  2382.  
  2383.     friend AstBlock;
  2384.  
  2385. public:
  2386.     AstSwitchBlockStatement(StoragePool *pool_) : pool(pool_),
  2387.                                                   block_statements(NULL),
  2388.                                                   switch_labels(NULL),
  2389.                                                   locally_defined_variables(NULL)
  2390.     {
  2391.         Ast::kind = Ast::SWITCH_BLOCK;
  2392.         Ast::class_tag = Ast::NO_TAG;
  2393.         Ast::generated = 0;
  2394.     }
  2395.  
  2396.     virtual ~AstSwitchBlockStatement();
  2397.  
  2398.     inline AstStatement *&Statement(int i) { return (*block_statements)[i]; }
  2399.     inline int NumStatements() { return (block_statements ? block_statements -> Length() : 0); }
  2400.     inline void AllocateBlockStatements(int estimate = 0);
  2401.     inline void AddStatement(AstStatement *);
  2402.  
  2403.     inline Ast *&SwitchLabel(int i) { return (*switch_labels)[i]; }
  2404.     inline int NumSwitchLabels() { return (switch_labels ? switch_labels -> Length() : 0); }
  2405.     inline void AllocateSwitchLabels(int estimate = 0);
  2406.     inline void AddSwitchLabel(Ast *);
  2407.  
  2408.     inline VariableSymbol *&LocallyDefinedVariable(int i) { return (*locally_defined_variables)[i]; }
  2409.     inline int NumLocallyDefinedVariables() { return (locally_defined_variables ? locally_defined_variables -> Length() : 0); }
  2410.  
  2411. #ifdef TEST
  2412.     virtual void Print(LexStream &);
  2413.     virtual void Unparse(Ostream &, LexStream &);
  2414. #endif
  2415.  
  2416.     virtual Ast *Clone(StoragePool *);
  2417.  
  2418.     virtual LexStream::TokenIndex LeftToken()
  2419.     {
  2420.         return SwitchLabel(0) -> LeftToken();
  2421.     }
  2422.     virtual LexStream::TokenIndex RightToken()
  2423.     {
  2424.         return Statement(NumStatements() - 1) -> RightToken();
  2425.     }
  2426. };
  2427.  
  2428.  
  2429. class CaseElement
  2430. {
  2431. public:
  2432.     AstSwitchBlockStatement *switch_block_statement;
  2433.     AstExpression *expression;
  2434.     int index;
  2435.  
  2436.     int Value() { return ((IntLiteralValue *) (expression -> value)) -> value; }
  2437. };
  2438.  
  2439. //
  2440. // SwitchStatement --> <SWITCH, Label_opt, switch_token, Expression, {_token, SwitchBlockStatements, SwitchLabels_opt, }_token>
  2441. //
  2442. class AstSwitchStatement : public AstStatement
  2443. {
  2444.     AstArray<CaseElement *> *cases;
  2445.  
  2446. public:
  2447.     CaseElement default_case;
  2448.  
  2449.     LexStream::TokenIndex switch_token;
  2450.     AstExpression *expression;
  2451.     AstBlock *switch_block;
  2452.  
  2453.     AstSwitchStatement(StoragePool *pool_) : cases(NULL)
  2454.     {
  2455.         Ast::kind = Ast::SWITCH;
  2456.         Ast::class_tag = Ast::STATEMENT;
  2457.         Ast::generated = 0;
  2458.         AstStatement::pool = pool_;
  2459.         AstStatement::is_reachable = false;
  2460.         AstStatement::can_complete_normally = false;
  2461.         AstStatement::defined_variables = NULL;
  2462.     }
  2463.  
  2464.     virtual ~AstSwitchStatement();
  2465.  
  2466.     inline CaseElement *&Case(int i) { return (*cases)[i]; }
  2467.     inline int NumCases() { return (cases ? cases -> Length() : 0); }
  2468.     inline void AllocateCases(int estimate = 0);
  2469.     inline void AddCase(CaseElement *);
  2470.  
  2471.     void SortCases();
  2472.  
  2473. #ifdef TEST
  2474.     virtual void Print(LexStream &);
  2475.     virtual void Unparse(Ostream &, LexStream &);
  2476. #endif
  2477.  
  2478.     virtual Ast *Clone(StoragePool *);
  2479.  
  2480.     virtual LexStream::TokenIndex LeftToken()
  2481.     {
  2482.         return switch_token;
  2483.     }
  2484.     virtual LexStream::TokenIndex RightToken() { return switch_block -> RightToken(); }
  2485. };
  2486.  
  2487.  
  2488. //
  2489. // WhileStatement --> <WHILE, Label_opt, while_token, Expression, Statement>
  2490. //
  2491. class AstWhileStatement : public AstStatement
  2492. {
  2493. public:
  2494.     LexStream::TokenIndex while_token;
  2495.     AstExpression *expression;
  2496.     AstStatement *statement;
  2497.  
  2498.     AstWhileStatement(StoragePool *pool_)
  2499.     {
  2500.         Ast::kind = Ast::WHILE;
  2501.         Ast::class_tag = Ast::STATEMENT;
  2502.         Ast::generated = 0;
  2503.         AstStatement::pool = pool_;
  2504.         AstStatement::is_reachable = false;
  2505.         AstStatement::can_complete_normally = false;
  2506.         AstStatement::defined_variables = NULL;
  2507.     }
  2508.  
  2509.     virtual ~AstWhileStatement();
  2510.  
  2511. #ifdef TEST
  2512.     virtual void Print(LexStream &);
  2513.     virtual void Unparse(Ostream &, LexStream &);
  2514. #endif
  2515.  
  2516.     virtual Ast *Clone(StoragePool *);
  2517.  
  2518.     virtual LexStream::TokenIndex LeftToken()
  2519.     {
  2520.         return while_token;
  2521.     }
  2522.     virtual LexStream::TokenIndex RightToken() { return statement -> RightToken(); }
  2523. };
  2524.  
  2525.  
  2526. //
  2527. // DoStatement --> <DO, Label_opt, do_token, Expression, Statement, ;_token>
  2528. //
  2529. class AstDoStatement : public AstStatement
  2530. {
  2531. public:
  2532.     LexStream::TokenIndex do_token;
  2533.     AstStatement *statement;
  2534.     LexStream::TokenIndex while_token;
  2535.     AstExpression *expression;
  2536.     LexStream::TokenIndex semicolon_token;
  2537.  
  2538.     AstDoStatement(StoragePool *pool_)
  2539.     {
  2540.         Ast::kind = Ast::DO;
  2541.         Ast::class_tag = Ast::STATEMENT;
  2542.         Ast::generated = 0;
  2543.         AstStatement::pool = pool_;
  2544.         AstStatement::is_reachable = false;
  2545.         AstStatement::can_complete_normally = false;
  2546.         AstStatement::defined_variables = NULL;
  2547.     }
  2548.  
  2549.     virtual ~AstDoStatement();
  2550.  
  2551. #ifdef TEST
  2552.     virtual void Print(LexStream &);
  2553.     virtual void Unparse(Ostream &, LexStream &);
  2554. #endif
  2555.  
  2556.     virtual Ast *Clone(StoragePool *);
  2557.  
  2558.     virtual LexStream::TokenIndex LeftToken()
  2559.     {
  2560.         return do_token;
  2561.     }
  2562.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2563. };
  2564.  
  2565.  
  2566. //
  2567. // ForStatement --> <FOR, Label_opt, for_token, ForInits, Expression_opt, ForUpdates, Statement>
  2568. //
  2569. // ForInit --> ExpressionStatement
  2570. //           | LocalVariableDeclarationStatement
  2571. //
  2572. // ForUpdate --> ExpressionStatement
  2573. //
  2574. class AstForStatement : public AstStatement
  2575. {
  2576. private:
  2577.  
  2578.     AstArray<AstStatement *> *for_init_statements;
  2579.     AstArray<AstExpressionStatement *> *for_update_statements;
  2580.  
  2581. public:
  2582.     LexStream::TokenIndex for_token;
  2583.     AstExpression *end_expression_opt;
  2584.     AstStatement *statement;
  2585.  
  2586.     AstForStatement(StoragePool *pool_) : for_init_statements(NULL),
  2587.                                           for_update_statements(NULL)
  2588.     {
  2589.         Ast::kind = Ast::FOR;
  2590.         Ast::class_tag = Ast::STATEMENT;
  2591.         Ast::generated = 0;
  2592.         AstStatement::pool = pool_;
  2593.         AstStatement::is_reachable = false;
  2594.         AstStatement::can_complete_normally = false;
  2595.         AstStatement::defined_variables = NULL;
  2596.     }
  2597.  
  2598.     virtual ~AstForStatement();
  2599.  
  2600.     inline AstStatement *&ForInitStatement(int i) { return (*for_init_statements)[i]; }
  2601.     inline int NumForInitStatements() { return (for_init_statements ? for_init_statements -> Length() : 0); }
  2602.     inline void AllocateForInitStatements(int estimate = 0);
  2603.     inline void AddForInitStatement(AstStatement *);
  2604.  
  2605.     inline AstExpressionStatement *&ForUpdateStatement(int i) { return (*for_update_statements)[i]; }
  2606.     inline int NumForUpdateStatements() { return (for_update_statements ? for_update_statements -> Length() : 0); }
  2607.     inline void AllocateForUpdateStatements(int estimate = 0);
  2608.     inline void AddForUpdateStatement(AstExpressionStatement *);
  2609.  
  2610. #ifdef TEST
  2611.     virtual void Print(LexStream &);
  2612.     virtual void Unparse(Ostream &, LexStream &);
  2613. #endif
  2614.  
  2615.     virtual Ast *Clone(StoragePool *);
  2616.  
  2617.     virtual LexStream::TokenIndex LeftToken()
  2618.     {
  2619.         return for_token;
  2620.     }
  2621.     virtual LexStream::TokenIndex RightToken() { return statement -> RightToken(); }
  2622. };
  2623.  
  2624.  
  2625. //
  2626. // BreakStatement --> <BREAK, Label_opt, break_token, identifier_token_opt, ;_token>
  2627. //
  2628. class AstBreakStatement : public AstStatement
  2629. {
  2630. public:
  2631.     LexStream::TokenIndex break_token;
  2632.     LexStream::TokenIndex identifier_token_opt;
  2633.     LexStream::TokenIndex semicolon_token;
  2634.     int nesting_level;
  2635.  
  2636.     AstBreakStatement(StoragePool *pool_)
  2637.     {
  2638.         Ast::kind = Ast::BREAK;
  2639.         Ast::class_tag = Ast::STATEMENT;
  2640.         Ast::generated = 0;
  2641.         AstStatement::pool = pool_;
  2642.         AstStatement::is_reachable = false;
  2643.         AstStatement::can_complete_normally = false;
  2644.         AstStatement::defined_variables = NULL;
  2645.     }
  2646.  
  2647.     virtual ~AstBreakStatement();
  2648.  
  2649. #ifdef TEST
  2650.     virtual void Print(LexStream &);
  2651.     virtual void Unparse(Ostream &, LexStream &);
  2652. #endif
  2653.  
  2654.     virtual Ast *Clone(StoragePool *);
  2655.  
  2656.     virtual LexStream::TokenIndex LeftToken()
  2657.     {
  2658.         return break_token;
  2659.     }
  2660.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2661. };
  2662.  
  2663. //
  2664. // ContinueStatement --> <CONTINUE, Label_opt, continue_token, SimpleName_opt, ;_token>
  2665. //
  2666. class AstContinueStatement : public AstStatement
  2667. {
  2668. public:
  2669.     LexStream::TokenIndex continue_token;
  2670.     LexStream::TokenIndex identifier_token_opt;
  2671.     LexStream::TokenIndex semicolon_token;
  2672.     int nesting_level;
  2673.  
  2674.     AstContinueStatement(StoragePool *pool_)
  2675.     {
  2676.         Ast::kind = Ast::CONTINUE;
  2677.         Ast::class_tag = Ast::STATEMENT;
  2678.         Ast::generated = 0;
  2679.         AstStatement::pool = pool_;
  2680.         AstStatement::is_reachable = false;
  2681.         AstStatement::can_complete_normally = false;
  2682.         AstStatement::defined_variables = NULL;
  2683.     }
  2684.  
  2685.     virtual ~AstContinueStatement();
  2686.  
  2687. #ifdef TEST
  2688.     virtual void Print(LexStream &);
  2689.     virtual void Unparse(Ostream &, LexStream &);
  2690. #endif
  2691.  
  2692.     virtual Ast *Clone(StoragePool *);
  2693.  
  2694.     virtual LexStream::TokenIndex LeftToken()
  2695.     {
  2696.         return continue_token;
  2697.     }
  2698.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2699. };
  2700.  
  2701.  
  2702. //
  2703. // ReturnStatement --> <RETURN, Label_opt, return_token, Expression_opt, ;_token>
  2704. //
  2705. class AstReturnStatement : public AstStatement
  2706. {
  2707. public:
  2708.     LexStream::TokenIndex return_token;
  2709.     AstExpression *expression_opt;
  2710.     LexStream::TokenIndex semicolon_token;
  2711.  
  2712.     AstReturnStatement(StoragePool *pool_)
  2713.     {
  2714.         Ast::kind = Ast::RETURN;
  2715.         Ast::class_tag = Ast::STATEMENT;
  2716.         Ast::generated = 0;
  2717.         AstStatement::pool = pool_;
  2718.         AstStatement::is_reachable = false;
  2719.         AstStatement::can_complete_normally = false;
  2720.         AstStatement::defined_variables = NULL;
  2721.     }
  2722.  
  2723.     virtual ~AstReturnStatement();
  2724.  
  2725. #ifdef TEST
  2726.     virtual void Print(LexStream &);
  2727.     virtual void Unparse(Ostream &, LexStream &);
  2728. #endif
  2729.  
  2730.     virtual Ast *Clone(StoragePool *);
  2731.  
  2732.     virtual LexStream::TokenIndex LeftToken()
  2733.     {
  2734.         return return_token;
  2735.     }
  2736.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2737. };
  2738.  
  2739.  
  2740. //
  2741. // ThrowStatement --> <THROW, Label_opt, throw_token, Expression, ;_token>
  2742. //
  2743. class AstThrowStatement : public AstStatement
  2744. {
  2745. public:
  2746.     LexStream::TokenIndex throw_token;
  2747.     AstExpression *expression;
  2748.     LexStream::TokenIndex semicolon_token;
  2749.  
  2750.     AstThrowStatement(StoragePool *pool_)
  2751.     {
  2752.         Ast::kind = Ast::THROW;
  2753.         Ast::class_tag = Ast::STATEMENT;
  2754.         Ast::generated = 0;
  2755.         AstStatement::pool = pool_;
  2756.         AstStatement::is_reachable = false;
  2757.         AstStatement::can_complete_normally = false;
  2758.         AstStatement::defined_variables = NULL;
  2759.     }
  2760.  
  2761.     virtual ~AstThrowStatement();
  2762.  
  2763. #ifdef TEST
  2764.     virtual void Print(LexStream &);
  2765.     virtual void Unparse(Ostream &, LexStream &);
  2766. #endif
  2767.  
  2768.     virtual Ast *Clone(StoragePool *);
  2769.  
  2770.     virtual LexStream::TokenIndex LeftToken()
  2771.     {
  2772.         return throw_token;
  2773.     }
  2774.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2775. };
  2776.  
  2777.  
  2778. //
  2779. // SynchronizedStatement --> <SYNCHRONIZED_STATEMENT, Label_opt, synchronized_token, Expression, Block>
  2780. //
  2781. class AstSynchronizedStatement : public AstStatement
  2782. {
  2783. public:
  2784.     LexStream::TokenIndex synchronized_token;
  2785.     AstExpression *expression;
  2786.     AstBlock *block;
  2787.  
  2788.     AstSynchronizedStatement(StoragePool *pool_)
  2789.     {
  2790.         Ast::kind = Ast::SYNCHRONIZED_STATEMENT;
  2791.         Ast::class_tag = Ast::STATEMENT;
  2792.         Ast::generated = 0;
  2793.         AstStatement::pool = pool_;
  2794.         AstStatement::is_reachable = false;
  2795.         AstStatement::can_complete_normally = false;
  2796.         AstStatement::defined_variables = NULL;
  2797.     }
  2798.  
  2799.     virtual ~AstSynchronizedStatement();
  2800.  
  2801. #ifdef TEST
  2802.     virtual void Print(LexStream &);
  2803.     virtual void Unparse(Ostream &, LexStream &);
  2804. #endif
  2805.  
  2806.     virtual Ast *Clone(StoragePool *);
  2807.  
  2808.     virtual LexStream::TokenIndex LeftToken()
  2809.     {
  2810.         return synchronized_token;
  2811.     }
  2812.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  2813. };
  2814.  
  2815.  
  2816. //
  2817. // CatchClause --> <CATCH, catch_token, FormalParameter, Block>
  2818. //
  2819. class AstCatchClause : public Ast
  2820. {
  2821. public:
  2822.     VariableSymbol *parameter_symbol;
  2823.  
  2824.     LexStream::TokenIndex catch_token;
  2825.     AstFormalParameter *formal_parameter;
  2826.     AstBlock *block;
  2827.  
  2828.     AstCatchClause() : parameter_symbol(NULL)
  2829.     {
  2830.         Ast::kind = Ast::CATCH;
  2831.         Ast::class_tag = Ast::NO_TAG;
  2832.         Ast::generated = 0;
  2833.     }
  2834.  
  2835.     virtual ~AstCatchClause();
  2836.  
  2837. #ifdef TEST
  2838.     virtual void Print(LexStream &);
  2839.     virtual void Unparse(Ostream &, LexStream &);
  2840. #endif
  2841.  
  2842.     virtual Ast *Clone(StoragePool *);
  2843.  
  2844.     virtual LexStream::TokenIndex LeftToken() { return catch_token; }
  2845.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  2846. };
  2847.  
  2848.  
  2849. //
  2850. // FinallyClause --> <FINALLY, finally_token, Block>
  2851. //
  2852. class AstFinallyClause : public Ast
  2853. {
  2854. public:
  2855.     LexStream::TokenIndex finally_token;
  2856.     AstBlock *block;
  2857.  
  2858.     AstFinallyClause()
  2859.     {
  2860.         Ast::kind = Ast::FINALLY;
  2861.         Ast::class_tag = Ast::NO_TAG;
  2862.         Ast::generated = 0;
  2863.     }
  2864.  
  2865.     virtual ~AstFinallyClause();
  2866.  
  2867. #ifdef TEST
  2868.     virtual void Print(LexStream &);
  2869.     virtual void Unparse(Ostream &, LexStream &);
  2870. #endif
  2871.  
  2872.     virtual Ast *Clone(StoragePool *);
  2873.  
  2874.     virtual LexStream::TokenIndex LeftToken() { return finally_token; }
  2875.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  2876. };
  2877.  
  2878.  
  2879. //
  2880. // TryStatement --> <TRY, Label_opt, try-token, Block CatchClauses, FinallyClause_opt>
  2881. //
  2882. class AstTryStatement : public AstStatement
  2883. {
  2884. private:
  2885.  
  2886.     AstArray<AstCatchClause *> *catch_clauses;
  2887.  
  2888. public:
  2889.     LexStream::TokenIndex try_token;
  2890.     AstBlock *block;
  2891.     AstFinallyClause *finally_clause_opt;
  2892.  
  2893.     AstTryStatement(StoragePool *pool_) : catch_clauses(NULL)
  2894.     {
  2895.         Ast::kind = Ast::TRY;
  2896.         Ast::class_tag = Ast::STATEMENT;
  2897.         Ast::generated = 0;
  2898.         AstStatement::pool = pool_;
  2899.         AstStatement::is_reachable = false;
  2900.         AstStatement::can_complete_normally = false;
  2901.         AstStatement::defined_variables = NULL;
  2902.     }
  2903.  
  2904.     virtual ~AstTryStatement();
  2905.  
  2906.     inline AstCatchClause *&CatchClause(int i) { return (*catch_clauses)[i]; }
  2907.     inline int NumCatchClauses() { return (catch_clauses ? catch_clauses -> Length() : 0); }
  2908.     inline void AllocateCatchClauses(int estimate = 0);
  2909.     inline void AddCatchClause(AstCatchClause *);
  2910.  
  2911. #ifdef TEST
  2912.     virtual void Print(LexStream &);
  2913.     virtual void Unparse(Ostream &, LexStream &);
  2914. #endif
  2915.  
  2916.     virtual Ast *Clone(StoragePool *);
  2917.  
  2918.     virtual LexStream::TokenIndex LeftToken()
  2919.     {
  2920.         return try_token;
  2921.     }
  2922.     virtual LexStream::TokenIndex RightToken()
  2923.     {
  2924.         //
  2925.         // when the Finally clause is null, there must be one or more catch clauses
  2926.         //
  2927.         return (finally_clause_opt ? finally_clause_opt -> RightToken() : CatchClause(NumCatchClauses() - 1) -> RightToken());
  2928.     }
  2929. };
  2930.  
  2931. //
  2932. // Expression --> Primary
  2933. //              | UnaryExpression
  2934. //              | BinaryExpression
  2935. //              | ConditionalExpression
  2936. //              | AssignmentExpression
  2937. //
  2938. // Primary --> Literal
  2939. //           | NullLiteral
  2940. //           | ThisExpression
  2941. //           | SuperExpression
  2942. //           | ParenthesizedExpression
  2943. //           | ClassInstanceCreationExpression
  2944. //           | ArrayCreationExpression
  2945. //           | FieldAccess
  2946. //           | MethodInvocation
  2947. //           | ArrayAccess
  2948. //
  2949. // Literal --> IntegerLiteral
  2950. //           | LongLiteral
  2951. //           | FloatingPointLiteral
  2952. //           | DoubleLiteral
  2953. //           | BooleanLiteral
  2954. //           | StringLiteral
  2955. //           | CharacterLiteral
  2956. //
  2957. // BooleanLiteral --> TrueLiteral
  2958. //                  | FalseLiteral
  2959. //
  2960.  
  2961. //
  2962. // IntegerLiteral --> <INTEGER_LITERAL, integer_literal_token, value>
  2963. //
  2964. class AstIntegerLiteral : public AstExpression
  2965. {
  2966. public:
  2967.     LexStream::TokenIndex integer_literal_token;
  2968.  
  2969.     AstIntegerLiteral(LexStream::TokenIndex token_) : integer_literal_token(token_)
  2970.     {
  2971.         Ast::kind = Ast::INTEGER_LITERAL;
  2972.         Ast::class_tag = Ast::EXPRESSION;
  2973.         Ast::generated = 0;
  2974.         AstExpression::value = NULL;
  2975.         AstExpression::symbol = NULL;
  2976.     }
  2977.  
  2978.     virtual ~AstIntegerLiteral();
  2979.  
  2980. #ifdef TEST
  2981.     virtual void Print(LexStream &);
  2982.     virtual void Unparse(Ostream &, LexStream &);
  2983. #endif
  2984.  
  2985.     virtual Ast *Clone(StoragePool *);
  2986.  
  2987.     virtual LexStream::TokenIndex LeftToken()  { return integer_literal_token; }
  2988.     virtual LexStream::TokenIndex RightToken() { return integer_literal_token; }
  2989. };
  2990.  
  2991.  
  2992. //
  2993. // LongLiteral --> <LONG_LITERAL, long_literal_token, value>
  2994. //
  2995. class AstLongLiteral : public AstExpression
  2996. {
  2997. public:
  2998.     LexStream::TokenIndex long_literal_token;
  2999.  
  3000.     AstLongLiteral(LexStream::TokenIndex token_) : long_literal_token(token_)
  3001.     {
  3002.         Ast::kind = Ast::LONG_LITERAL;
  3003.         Ast::class_tag = Ast::EXPRESSION;
  3004.         Ast::generated = 0;
  3005.         AstExpression::value = NULL;
  3006.         AstExpression::symbol = NULL;
  3007.     }
  3008.  
  3009.     virtual ~AstLongLiteral();
  3010.  
  3011. #ifdef TEST
  3012.     virtual void Print(LexStream &);
  3013.     virtual void Unparse(Ostream &, LexStream &);
  3014. #endif
  3015.  
  3016.     virtual Ast *Clone(StoragePool *);
  3017.  
  3018.     virtual LexStream::TokenIndex LeftToken()  { return long_literal_token; }
  3019.     virtual LexStream::TokenIndex RightToken() { return long_literal_token; }
  3020. };
  3021.  
  3022.  
  3023. //
  3024. // FloatingPointLiteral --> <FLOATING_POINT_LITERAL, Literal, value>
  3025. //
  3026. class AstFloatingPointLiteral : public AstExpression
  3027. {
  3028. public:
  3029.     LexStream::TokenIndex floating_point_literal_token;
  3030.  
  3031.     AstFloatingPointLiteral(LexStream::TokenIndex token_) : floating_point_literal_token(token_)
  3032.     {
  3033.         Ast::kind = Ast::FLOATING_POINT_LITERAL;
  3034.         Ast::class_tag = Ast::EXPRESSION;
  3035.         Ast::generated = 0;
  3036.         AstExpression::value = NULL;
  3037.         AstExpression::symbol = NULL;
  3038.     }
  3039.  
  3040.     virtual ~AstFloatingPointLiteral();
  3041.  
  3042. #ifdef TEST
  3043.     virtual void Print(LexStream &);
  3044.     virtual void Unparse(Ostream &, LexStream &);
  3045. #endif
  3046.  
  3047.     virtual Ast *Clone(StoragePool *);
  3048.  
  3049.     virtual LexStream::TokenIndex LeftToken()  { return floating_point_literal_token; }
  3050.     virtual LexStream::TokenIndex RightToken() { return floating_point_literal_token; }
  3051. };
  3052.  
  3053. //
  3054. // DoubleLiteral --> <DOUBLE_LITERAL, Literal, value>
  3055. //
  3056. class AstDoubleLiteral : public AstExpression
  3057. {
  3058. public:
  3059.     LexStream::TokenIndex double_literal_token;
  3060.  
  3061.     AstDoubleLiteral(LexStream::TokenIndex token_) : double_literal_token(token_)
  3062.     {
  3063.         Ast::kind = Ast::DOUBLE_LITERAL;
  3064.         Ast::class_tag = Ast::EXPRESSION;
  3065.         Ast::generated = 0;
  3066.         AstExpression::value = NULL;
  3067.         AstExpression::symbol = NULL;
  3068.     }
  3069.  
  3070.     virtual ~AstDoubleLiteral();
  3071.  
  3072. #ifdef TEST
  3073.     virtual void Print(LexStream &);
  3074.     virtual void Unparse(Ostream &, LexStream &);
  3075. #endif
  3076.  
  3077.     virtual Ast *Clone(StoragePool *);
  3078.  
  3079.     virtual LexStream::TokenIndex LeftToken()  { return double_literal_token; }
  3080.     virtual LexStream::TokenIndex RightToken() { return double_literal_token; }
  3081. };
  3082.  
  3083. //
  3084. // TrueLiteral --> <TRUE_LITERAL, Literal, value>
  3085. //
  3086. class AstTrueLiteral : public AstExpression
  3087. {
  3088. public:
  3089.     LexStream::TokenIndex true_literal_token;
  3090.  
  3091.     AstTrueLiteral(LexStream::TokenIndex token_) : true_literal_token(token_)
  3092.     {
  3093.         Ast::kind = Ast::TRUE_LITERAL;
  3094.         Ast::class_tag = Ast::EXPRESSION;
  3095.         Ast::generated = 0;
  3096.         AstExpression::value = NULL;
  3097.         AstExpression::symbol = NULL;
  3098.     }
  3099.  
  3100.     virtual ~AstTrueLiteral();
  3101.  
  3102. #ifdef TEST
  3103.     virtual void Print(LexStream &);
  3104.     virtual void Unparse(Ostream &, LexStream &);
  3105. #endif
  3106.  
  3107.     virtual Ast *Clone(StoragePool *);
  3108.  
  3109.     virtual LexStream::TokenIndex LeftToken()  { return true_literal_token; }
  3110.     virtual LexStream::TokenIndex RightToken() { return true_literal_token; }
  3111. };
  3112.  
  3113. //
  3114. // FalseLiteral --> <FALSE_LITERAL, Literal, value>
  3115. //
  3116. class AstFalseLiteral : public AstExpression
  3117. {
  3118. public:
  3119.     LexStream::TokenIndex false_literal_token;
  3120.  
  3121.     AstFalseLiteral(LexStream::TokenIndex token_) : false_literal_token(token_)
  3122.     {
  3123.         Ast::kind = Ast::FALSE_LITERAL;
  3124.         Ast::class_tag = Ast::EXPRESSION;
  3125.         Ast::generated = 0;
  3126.         AstExpression::value = NULL;
  3127.         AstExpression::symbol = NULL;
  3128.     }
  3129.  
  3130.     virtual ~AstFalseLiteral();
  3131.  
  3132. #ifdef TEST
  3133.     virtual void Print(LexStream &);
  3134.     virtual void Unparse(Ostream &, LexStream &);
  3135. #endif
  3136.  
  3137.     virtual Ast *Clone(StoragePool *);
  3138.  
  3139.     virtual LexStream::TokenIndex LeftToken()  { return false_literal_token; }
  3140.     virtual LexStream::TokenIndex RightToken() { return false_literal_token; }
  3141. };
  3142.  
  3143. //
  3144. // StringLiteral --> <STRING_LITERAL, Literal, value>
  3145. //
  3146. class AstStringLiteral : public AstExpression
  3147. {
  3148. public:
  3149.     LexStream::TokenIndex string_literal_token;
  3150.  
  3151.     AstStringLiteral(LexStream::TokenIndex token_) : string_literal_token(token_)
  3152.     {
  3153.         Ast::kind = Ast::STRING_LITERAL;
  3154.         Ast::class_tag = Ast::EXPRESSION;
  3155.         Ast::generated = 0;
  3156.         AstExpression::value = NULL;
  3157.         AstExpression::symbol = NULL;
  3158.     }
  3159.  
  3160.     virtual ~AstStringLiteral();
  3161.  
  3162. #ifdef TEST
  3163.     virtual void Print(LexStream &);
  3164.     virtual void Unparse(Ostream &, LexStream &);
  3165. #endif
  3166.  
  3167.     virtual Ast *Clone(StoragePool *);
  3168.  
  3169.     virtual LexStream::TokenIndex LeftToken()  { return string_literal_token; }
  3170.     virtual LexStream::TokenIndex RightToken() { return string_literal_token; }
  3171. };
  3172.  
  3173. //
  3174. // CharacterLiteral --> <CHARACTER_LITERAL, literal_token, value>
  3175. //
  3176. class AstCharacterLiteral : public AstExpression
  3177. {
  3178. public:
  3179.     LexStream::TokenIndex character_literal_token;
  3180.  
  3181.     AstCharacterLiteral(LexStream::TokenIndex token_) : character_literal_token(token_)
  3182.     {
  3183.         Ast::kind = Ast::CHARACTER_LITERAL;
  3184.         Ast::class_tag = Ast::EXPRESSION;
  3185.         Ast::generated = 0;
  3186.         AstExpression::value = NULL;
  3187.         AstExpression::symbol = NULL;
  3188.     }
  3189.  
  3190.     virtual ~AstCharacterLiteral();
  3191.  
  3192. #ifdef TEST
  3193.     virtual void Print(LexStream &);
  3194.     virtual void Unparse(Ostream &, LexStream &);
  3195. #endif
  3196.  
  3197.     virtual Ast *Clone(StoragePool *);
  3198.  
  3199.     virtual LexStream::TokenIndex LeftToken()  { return character_literal_token; }
  3200.     virtual LexStream::TokenIndex RightToken() { return character_literal_token; }
  3201. };
  3202.  
  3203. //
  3204. // NullLiteral --> <NULL_EXPRESSION, null_token>
  3205. //
  3206. class AstNullLiteral : public AstExpression
  3207. {
  3208. public:
  3209.     LexStream::TokenIndex null_token;
  3210.  
  3211.     AstNullLiteral(LexStream::TokenIndex token_) : null_token(token_)
  3212.     {
  3213.         Ast::kind = Ast::NULL_LITERAL;
  3214.         Ast::class_tag = Ast::EXPRESSION;
  3215.         Ast::generated = 0;
  3216.         AstExpression::value = NULL;
  3217.         AstExpression::symbol = NULL;
  3218.     }
  3219.  
  3220.     virtual ~AstNullLiteral();
  3221.  
  3222. #ifdef TEST
  3223.     virtual void Print(LexStream &);
  3224.     virtual void Unparse(Ostream &, LexStream &);
  3225. #endif
  3226.  
  3227.     virtual Ast *Clone(StoragePool *);
  3228.  
  3229.     virtual LexStream::TokenIndex LeftToken()  { return null_token; }
  3230.     virtual LexStream::TokenIndex RightToken() { return null_token; }
  3231. };
  3232.  
  3233. //
  3234. // ThisExpression --> <THIS, this_token>
  3235. //
  3236. class AstThisExpression : public AstExpression
  3237. {
  3238. public:
  3239.     LexStream::TokenIndex this_token;
  3240.  
  3241.     AstThisExpression(LexStream::TokenIndex token_) : this_token(token_)
  3242.     {
  3243.         Ast::kind = Ast::THIS_EXPRESSION;
  3244.         Ast::class_tag = Ast::EXPRESSION;
  3245.         Ast::generated = 0;
  3246.         AstExpression::value = NULL;
  3247.         AstExpression::symbol = NULL;
  3248.     }
  3249.  
  3250.     virtual ~AstThisExpression();
  3251.  
  3252. #ifdef TEST
  3253.     virtual void Print(LexStream &);
  3254.     virtual void Unparse(Ostream &, LexStream &);
  3255. #endif
  3256.  
  3257.     virtual Ast *Clone(StoragePool *);
  3258.  
  3259.     virtual LexStream::TokenIndex LeftToken()  { return this_token; }
  3260.     virtual LexStream::TokenIndex RightToken() { return this_token; }
  3261. };
  3262.  
  3263.  
  3264. //
  3265. // SuperExpression --> <SUPER, super_token>
  3266. //
  3267. class AstSuperExpression : public AstExpression
  3268. {
  3269. public:
  3270.     LexStream::TokenIndex super_token;
  3271.  
  3272.     AstSuperExpression(LexStream::TokenIndex token_) : super_token(token_)
  3273.     {
  3274.         Ast::kind = Ast::SUPER_EXPRESSION;
  3275.         Ast::class_tag = Ast::EXPRESSION;
  3276.         Ast::generated = 0;
  3277.         AstExpression::value = NULL;
  3278.         AstExpression::symbol = NULL;
  3279.     }
  3280.  
  3281.     virtual ~AstSuperExpression();
  3282.  
  3283. #ifdef TEST
  3284.     virtual void Print(LexStream &);
  3285.     virtual void Unparse(Ostream &, LexStream &);
  3286. #endif
  3287.  
  3288.     virtual Ast *Clone(StoragePool *);
  3289.  
  3290.     virtual LexStream::TokenIndex LeftToken()  { return super_token; }
  3291.     virtual LexStream::TokenIndex RightToken() { return super_token; }
  3292. };
  3293.  
  3294.  
  3295. //
  3296. // ParenthesizedExpression --> <PARENTHESIZED_EXPRESSION, (_token, Expression, )_token>
  3297. //
  3298. class AstParenthesizedExpression : public AstExpression
  3299. {
  3300. public:
  3301.     LexStream::TokenIndex left_parenthesis_token;
  3302.     AstExpression *expression;
  3303.     LexStream::TokenIndex right_parenthesis_token;
  3304.  
  3305.     AstParenthesizedExpression()
  3306.     {
  3307.         Ast::kind = Ast::PARENTHESIZED_EXPRESSION;
  3308.         Ast::class_tag = Ast::EXPRESSION;
  3309.         Ast::generated = 0;
  3310.         AstExpression::value = NULL;
  3311.         AstExpression::symbol = NULL;
  3312.     }
  3313.  
  3314.     virtual ~AstParenthesizedExpression();
  3315.  
  3316. #ifdef TEST
  3317.     virtual void Print(LexStream &);
  3318.     virtual void Unparse(Ostream &, LexStream &);
  3319. #endif
  3320.  
  3321.     virtual Ast *Clone(StoragePool *);
  3322.  
  3323.     virtual LexStream::TokenIndex LeftToken()  { return left_parenthesis_token; }
  3324.     virtual LexStream::TokenIndex RightToken() { return right_parenthesis_token; }
  3325. };
  3326.  
  3327.  
  3328. //
  3329. // TypeExpression --> <TYPE, Type>
  3330. //
  3331. class AstTypeExpression : public AstExpression
  3332. {
  3333. public:
  3334.     Ast *type;
  3335.  
  3336.     AstTypeExpression(Ast *type_) : type(type_)
  3337.     {
  3338.         Ast::kind = Ast::TYPE;
  3339.         Ast::class_tag = Ast::EXPRESSION;
  3340.         Ast::generated = 0;
  3341.         AstExpression::value = NULL;
  3342.         AstExpression::symbol = NULL;
  3343.     }
  3344.  
  3345.     virtual ~AstTypeExpression();
  3346.  
  3347. #ifdef TEST
  3348.     virtual void Print(LexStream &);
  3349.     virtual void Unparse(Ostream &, LexStream &);
  3350. #endif
  3351.  
  3352.     virtual Ast *Clone(StoragePool *);
  3353.  
  3354.     virtual LexStream::TokenIndex LeftToken()  { return type -> LeftToken(); }
  3355.     virtual LexStream::TokenIndex RightToken() { return type -> RightToken(); }
  3356. };
  3357.  
  3358.  
  3359. //
  3360. // ClassInstanceCreationExpression --> <CLASS_CREATION, new_token, TypeExpression, (_token, Arguments, )_token>
  3361. //
  3362. // Sometimes, during semantic analysis an artificial base_opt expression is constructed.
  3363. // In such a case, the user can determine this condition by testing whether or not
  3364. // dot_token_opt is 0;
  3365. //
  3366. class AstClassInstanceCreationExpression : public AstExpression
  3367. {
  3368. private:
  3369.  
  3370.     StoragePool *pool;
  3371.     AstArray<AstExpression *> *arguments;
  3372.     AstArray<AstExpression *> *local_arguments_opt; // used only for local classes that use enclosed local variables
  3373.  
  3374.     bool add_null_argument;
  3375.  
  3376. public:
  3377.     AstExpression *base_opt;
  3378.     LexStream::TokenIndex dot_token_opt;
  3379.     LexStream::TokenIndex new_token;
  3380.     AstTypeExpression *class_type;
  3381.     LexStream::TokenIndex left_parenthesis_token;
  3382.     LexStream::TokenIndex right_parenthesis_token;
  3383.     AstClassBody *class_body_opt;
  3384.  
  3385.     AstClassInstanceCreationExpression(StoragePool *pool_) : pool(pool_),
  3386.                                                              arguments(NULL),
  3387.                                                              local_arguments_opt(NULL),
  3388.                                                              add_null_argument(false)
  3389.     {
  3390.         Ast::kind = Ast::CLASS_CREATION;
  3391.         Ast::class_tag = Ast::EXPRESSION;
  3392.         Ast::generated = 0;
  3393.         AstExpression::value = NULL;
  3394.         AstExpression::symbol = NULL;
  3395.     }
  3396.  
  3397.     virtual ~AstClassInstanceCreationExpression();
  3398.  
  3399.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  3400.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  3401.     inline void AllocateArguments(int estimate = 0);
  3402.     inline void AddArgument(AstExpression *);
  3403.  
  3404.     inline AstExpression *&LocalArgument(int i) { return (*local_arguments_opt)[i]; }
  3405.     inline int NumLocalArguments() { return (local_arguments_opt ? local_arguments_opt -> Length() : 0); }
  3406.     inline void AllocateLocalArguments(int estimate = 0);
  3407.     inline void AddLocalArgument(AstExpression *);
  3408.  
  3409.     inline void AddNullArgument() { add_null_argument = true; }
  3410.     inline bool NeedsExtraNullArgument() { return add_null_argument; }
  3411.  
  3412. #ifdef TEST
  3413.     virtual void Print(LexStream &);
  3414.     virtual void Unparse(Ostream &, LexStream &);
  3415. #endif
  3416.  
  3417.     virtual Ast *Clone(StoragePool *);
  3418.  
  3419.     virtual LexStream::TokenIndex LeftToken()
  3420.     {
  3421.         return (base_opt ? base_opt -> LeftToken() : new_token);
  3422.     }
  3423.     virtual LexStream::TokenIndex RightToken() { return (class_body_opt ? class_body_opt -> RightToken() : right_parenthesis_token); }
  3424. };
  3425.  
  3426.  
  3427. //
  3428. // DimExpr --> <DIM, [_token, Expression, ]_token>
  3429. //
  3430. class AstDimExpr : public Ast
  3431. {
  3432. public:
  3433.     LexStream::TokenIndex left_bracket_token;
  3434.     AstExpression *expression;
  3435.     LexStream::TokenIndex right_bracket_token;
  3436.  
  3437.     AstDimExpr()
  3438.     {
  3439.         Ast::kind = Ast::DIM;
  3440.         Ast::class_tag = Ast::NO_TAG;
  3441.         Ast::generated = 0;
  3442.     }
  3443.  
  3444.     virtual ~AstDimExpr();
  3445.  
  3446. #ifdef TEST
  3447.     virtual void Print(LexStream &);
  3448.     virtual void Unparse(Ostream &, LexStream &);
  3449. #endif
  3450.  
  3451.     virtual Ast *Clone(StoragePool *);
  3452.  
  3453.     virtual LexStream::TokenIndex LeftToken()  { return left_bracket_token; }
  3454.     virtual LexStream::TokenIndex RightToken() { return right_bracket_token; }
  3455. };
  3456.  
  3457.  
  3458. //
  3459. // ArrayCreationExpression --> <ARRAY_CREATION, new_token, Type, DimExprs, Brackets>
  3460. //
  3461. class AstArrayCreationExpression : public AstExpression
  3462. {
  3463. private:
  3464.  
  3465.     StoragePool *pool;
  3466.     AstArray<AstBrackets *> *brackets;
  3467.     AstArray<AstDimExpr *> *dim_exprs;
  3468.  
  3469. public:
  3470.     LexStream::TokenIndex new_token;
  3471.     Ast *array_type;
  3472.     AstArrayInitializer *array_initializer_opt;
  3473.  
  3474.     AstArrayCreationExpression(StoragePool *pool_) : pool(pool_),
  3475.                                                      brackets(NULL),
  3476.                                                      dim_exprs(NULL)
  3477.     {
  3478.         Ast::kind = Ast::ARRAY_CREATION;
  3479.         Ast::class_tag = Ast::EXPRESSION;
  3480.         Ast::generated = 0;
  3481.         AstExpression::value = NULL;
  3482.         AstExpression::symbol = NULL;
  3483.     }
  3484.  
  3485.     virtual ~AstArrayCreationExpression();
  3486.  
  3487.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  3488.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  3489.     inline void AllocateBrackets(int estimate = 0);
  3490.     inline void AddBrackets(AstBrackets *);
  3491.  
  3492.     inline AstDimExpr *&DimExpr(int i) { return (*dim_exprs)[i]; }
  3493.     inline int NumDimExprs() { return (dim_exprs ? dim_exprs -> Length() : 0); }
  3494.     inline void AllocateDimExprs(int estimate = 0);
  3495.     inline void AddDimExpr(AstDimExpr *);
  3496.  
  3497. #ifdef TEST
  3498.     virtual void Print(LexStream &);
  3499.     virtual void Unparse(Ostream &, LexStream &);
  3500. #endif
  3501.  
  3502.     virtual Ast *Clone(StoragePool *);
  3503.  
  3504.     virtual LexStream::TokenIndex LeftToken()  { return new_token; }
  3505.     virtual LexStream::TokenIndex RightToken()
  3506.     {
  3507.         return (array_initializer_opt ? array_initializer_opt -> RightToken()
  3508.                                       : (NumBrackets() > 0 ? Brackets(NumBrackets() - 1) -> RightToken()
  3509.                                                            : DimExpr(NumDimExprs() - 1) -> RightToken()));
  3510.     }
  3511. };
  3512.  
  3513.  
  3514. //
  3515. // FieldAccess --> <DOT, Base, ._token, SimpleName>
  3516. //               | <DOT, TypeExpression, ._token, class_token>
  3517. //               | <DOT, TypeExpression, ._token, this_token>
  3518. //
  3519. // SuperField --> <DOT, TypeExpression, ._token, super_token>
  3520. //
  3521. // Base --> Primary
  3522. //        | Name
  3523. //
  3524. class AstFieldAccess : public AstExpression
  3525. {
  3526. public:
  3527.     enum FieldAccessTag
  3528.     {
  3529.         NONE,
  3530.         CLASS_TAG,
  3531.         THIS_TAG,
  3532.         SUPER_TAG,
  3533.  
  3534.         _num_kinds
  3535.     };
  3536.  
  3537.     AstExpression *base;
  3538.     LexStream::TokenIndex dot_token;
  3539.     LexStream::TokenIndex identifier_token;
  3540.  
  3541.     //
  3542.     // When the right-side of a field access consists of
  3543.     // the keyword this, we resolve it either into a
  3544.     // "this" expression if it refers to "this" type or
  3545.     // to a method call that gives access to the relevant
  3546.     // (private) this$0.
  3547.     //
  3548.     // If the base expression of FieldAccess expression is
  3549.     // of the form expr.this.X, where X is a private variable
  3550.     // that is a member of an outer class, then we resolve it
  3551.     // into a method call to the read_mehod that gives access
  3552.     // to X. In some cases, we also need to resolve field accesses
  3553.     // of the form expr.class.
  3554.     //
  3555.     AstExpression *resolution_opt;
  3556.  
  3557.     AstFieldAccess(FieldAccessTag tag = NONE) : resolution_opt(NULL),
  3558.                                                 field_access_tag(tag)
  3559.     {
  3560.         Ast::kind = Ast::DOT;
  3561.         Ast::class_tag = Ast::EXPRESSION;
  3562.         Ast::generated = 0;
  3563.         AstExpression::value = NULL;
  3564.         AstExpression::symbol = NULL;
  3565.     }
  3566.  
  3567.     virtual ~AstFieldAccess();
  3568.  
  3569.     bool IsNameAccess()  { return field_access_tag == NONE; }
  3570.     bool IsThisAccess()  { return field_access_tag == THIS_TAG; }
  3571.     bool IsSuperAccess() { return field_access_tag == SUPER_TAG; }
  3572.     bool IsClassAccess() { return field_access_tag == CLASS_TAG; }
  3573.  
  3574. #ifdef TEST
  3575.     virtual void Print(LexStream &);
  3576.     virtual void Unparse(Ostream &, LexStream &);
  3577. #endif
  3578.  
  3579.     virtual Ast *Clone(StoragePool *);
  3580.  
  3581.     virtual LexStream::TokenIndex LeftToken()  { return base -> LeftToken(); }
  3582.     virtual LexStream::TokenIndex RightToken() { return identifier_token; }
  3583.  
  3584. private:
  3585.     FieldAccessTag field_access_tag;
  3586. };
  3587.  
  3588.  
  3589. //
  3590. // MethodInvocation --> <CALL, Method, (_token, Arguments, )_token>
  3591. //
  3592. // Method --> SimpleName
  3593. //          | FieldAccess
  3594. //
  3595. class AstMethodInvocation : public AstExpression
  3596. {
  3597. private:
  3598.  
  3599.     StoragePool *pool;
  3600.     AstArray<AstExpression *> *arguments;
  3601.  
  3602. public:
  3603.     AstExpression *method;
  3604.     LexStream::TokenIndex left_parenthesis_token;
  3605.     LexStream::TokenIndex right_parenthesis_token;
  3606.  
  3607.     //
  3608.     // When a method refers to a member in an enclosing scope,
  3609.     // it is mapped into a new expression that creates a path to
  3610.     // the member in question.
  3611.     //
  3612.     AstExpression *resolution_opt;
  3613.  
  3614.     AstMethodInvocation(StoragePool *pool_) : pool(pool_),
  3615.                                               arguments(NULL),
  3616.                                               resolution_opt(NULL)
  3617.     {
  3618.         Ast::kind = Ast::CALL;
  3619.         Ast::class_tag = Ast::EXPRESSION;
  3620.         Ast::generated = 0;
  3621.         AstExpression::value = NULL;
  3622.         AstExpression::symbol = NULL;
  3623.     }
  3624.  
  3625.     virtual ~AstMethodInvocation();
  3626.  
  3627.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  3628.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  3629.     inline void AllocateArguments(int estimate = 0);
  3630.     inline void AddArgument(AstExpression *);
  3631.  
  3632. #ifdef TEST
  3633.     virtual void Print(LexStream &);
  3634.     virtual void Unparse(Ostream &, LexStream &);
  3635. #endif
  3636.  
  3637.     virtual Ast *Clone(StoragePool *);
  3638.  
  3639.     virtual LexStream::TokenIndex LeftToken() { return method -> LeftToken(); }
  3640.     virtual LexStream::TokenIndex RightToken() { return right_parenthesis_token; }
  3641. };
  3642.  
  3643.  
  3644. //
  3645. // ArrayAccess --> <ARRAY_ACCESS, Base, [_token, Expression, ]_token>
  3646. //
  3647. class AstArrayAccess : public AstExpression
  3648. {
  3649. public:
  3650.     AstExpression *base;
  3651.     LexStream::TokenIndex left_bracket_token;
  3652.     AstExpression *expression;
  3653.     LexStream::TokenIndex right_bracket_token;
  3654.  
  3655.     AstArrayAccess()
  3656.     {
  3657.         Ast::kind = Ast::ARRAY_ACCESS;
  3658.         Ast::class_tag = Ast::EXPRESSION;
  3659.         Ast::generated = 0;
  3660.         AstExpression::value = NULL;
  3661.         AstExpression::symbol = NULL;
  3662.     }
  3663.  
  3664.     virtual ~AstArrayAccess();
  3665.  
  3666. #ifdef TEST
  3667.     virtual void Print(LexStream &);
  3668.     virtual void Unparse(Ostream &, LexStream &);
  3669. #endif
  3670.  
  3671.     virtual Ast *Clone(StoragePool *);
  3672.  
  3673.     virtual LexStream::TokenIndex LeftToken() { return base -> LeftToken(); }
  3674.     virtual LexStream::TokenIndex RightToken() { return right_bracket_token; }
  3675. };
  3676.  
  3677.  
  3678. //
  3679. // UnaryExpression --> PreUnaryExpression
  3680. //                   | PostUnaryExpression
  3681. //                   | CastExpression
  3682. //
  3683. // PostUnaryExpression --> <POST_UNARY, PostUnaryTag, Expression, PostOperator>
  3684. //
  3685. // PostUnaryTag --> PLUSPLUS | MINUSMINUS
  3686. //
  3687. // PostOperator --> ++_token | --_token
  3688. //
  3689. class AstPostUnaryExpression : public AstExpression
  3690. {
  3691. public:
  3692.     enum PostUnaryExpressionTag
  3693.     {
  3694.         NONE,
  3695.         PLUSPLUS,
  3696.         MINUSMINUS,
  3697.  
  3698.         _num_kinds
  3699.     };
  3700.  
  3701.     PostUnaryExpressionTag post_unary_tag;
  3702.     AstExpression *expression;
  3703.     LexStream::TokenIndex post_operator_token;
  3704.  
  3705.     //
  3706.     // When the left-hand side of an assignment is a name that refers
  3707.     // to a private field in an enclosing scope, the access method
  3708.     // that gives write-permission to that field is recorded here.
  3709.     //
  3710.     MethodSymbol *write_method;
  3711.  
  3712.     AstPostUnaryExpression(PostUnaryExpressionTag tag_) : post_unary_tag(tag_),
  3713.                                                           write_method(NULL)
  3714.     {
  3715.         Ast::kind = Ast::POST_UNARY;
  3716.         Ast::class_tag = Ast::EXPRESSION;
  3717.         Ast::generated = 0;
  3718.         AstExpression::value = NULL;
  3719.         AstExpression::symbol = NULL;
  3720.     }
  3721.  
  3722.     virtual ~AstPostUnaryExpression();
  3723.  
  3724. #ifdef TEST
  3725.     virtual void Print(LexStream &);
  3726.     virtual void Unparse(Ostream &, LexStream &);
  3727. #endif
  3728.  
  3729.     virtual Ast *Clone(StoragePool *);
  3730.  
  3731.     virtual LexStream::TokenIndex LeftToken()  { return expression -> LeftToken(); }
  3732.     virtual LexStream::TokenIndex RightToken() { return post_operator_token; }
  3733. };
  3734.  
  3735.  
  3736. //
  3737. // PreUnaryExpression -->  <PRE_UNARY, PreUnaryTag, PreOperator, Expression>
  3738. //
  3739. // PreUnaryTag --> PLUS | MINUS | TWIDDLE | NOT | PLUSPLUS | MINUSMINUS
  3740. //
  3741. // PreOperator --> +_token | -_token | ~_token | !_token | ++_token | --_token
  3742. //
  3743. class AstPreUnaryExpression : public AstExpression
  3744. {
  3745. public:
  3746.     enum PreUnaryExpressionTag
  3747.     {
  3748.         NONE,
  3749.         PLUSPLUS,
  3750.         MINUSMINUS,
  3751.         PLUS,
  3752.         MINUS,
  3753.         TWIDDLE,
  3754.         NOT,
  3755.  
  3756.         _num_kinds
  3757.     };
  3758.  
  3759.     PreUnaryExpressionTag pre_unary_tag;
  3760.     LexStream::TokenIndex pre_operator_token;
  3761.     AstExpression *expression;
  3762.  
  3763.     //
  3764.     // When the left-hand side of an assignment is a name that refers
  3765.     // to a private field in an enclosing scope, the access method
  3766.     // that gives write-permission to that field is recorded here.
  3767.     //
  3768.     MethodSymbol *write_method;
  3769.  
  3770.     AstPreUnaryExpression(PreUnaryExpressionTag tag_) : pre_unary_tag(tag_),
  3771.                                                         write_method(NULL)
  3772.     {
  3773.         Ast::kind = Ast::PRE_UNARY;
  3774.         Ast::class_tag = Ast::EXPRESSION;
  3775.         Ast::generated = 0;
  3776.         AstExpression::value = NULL;
  3777.         AstExpression::symbol = NULL;
  3778.     }
  3779.  
  3780.     virtual ~AstPreUnaryExpression();
  3781.  
  3782. #ifdef TEST
  3783.     virtual void Print(LexStream &);
  3784.     virtual void Unparse(Ostream &, LexStream &);
  3785. #endif
  3786.  
  3787.     virtual Ast *Clone(StoragePool *);
  3788.  
  3789.     virtual LexStream::TokenIndex LeftToken()  { return pre_operator_token; }
  3790.     virtual LexStream::TokenIndex RightToken() { return expression -> RightToken(); }
  3791. };
  3792.  
  3793.  
  3794. //
  3795. // CastExpression --> <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, Expression>
  3796. //
  3797. // cAstkind --> CAST
  3798. //             | CHECK_AND_CAST
  3799. //
  3800. // NOTE that the optional symbols above are absent only when the compiler inserts
  3801. // a CAST conversion node into the program.
  3802. //
  3803. class AstCastExpression : public AstExpression
  3804. {
  3805. private:
  3806.  
  3807.     StoragePool *pool;
  3808.     AstArray<AstBrackets *> *brackets;
  3809.  
  3810. public:
  3811.     LexStream::TokenIndex left_parenthesis_token_opt;
  3812.     Ast *type_opt;
  3813.     LexStream::TokenIndex right_parenthesis_token_opt;
  3814.     AstExpression *expression;
  3815.  
  3816.     AstCastExpression(StoragePool *pool_) : pool(pool_),
  3817.                                             brackets(NULL)
  3818.     {
  3819.         Ast::kind = Ast::CAST;
  3820.         Ast::class_tag = Ast::EXPRESSION;
  3821.         Ast::generated = 0;
  3822.         AstExpression::value = NULL;
  3823.         AstExpression::symbol = NULL;
  3824.     }
  3825.  
  3826.     virtual ~AstCastExpression();
  3827.  
  3828.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  3829.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  3830.     inline void AllocateBrackets(int estimate = 0);
  3831.     inline void AddBrackets(AstBrackets *);
  3832.  
  3833. #ifdef TEST
  3834.     virtual void Print(LexStream &);
  3835.     virtual void Unparse(Ostream &, LexStream &);
  3836. #endif
  3837.  
  3838.     virtual Ast *Clone(StoragePool *);
  3839.  
  3840.     virtual LexStream::TokenIndex LeftToken()
  3841.     {
  3842.         return (left_parenthesis_token_opt ? left_parenthesis_token_opt : expression -> LeftToken());
  3843.     }
  3844.     virtual LexStream::TokenIndex RightToken() { return expression -> RightToken(); }
  3845. };
  3846.  
  3847.  
  3848. //
  3849. // BinaryExpression --> <BINARY, BinaryTag, LeftExpression, BinaryOperator, RightExpression>
  3850. //
  3851. // LeftExpression --> Expression
  3852. //
  3853. // RightExpression --> Expression
  3854. //                   | type
  3855. //
  3856. // BinaryTag --> STAR | SLASH | MOD | PLUS | MINUS | LEFT_SHIFT | RIGHT_SHIFT | UNSIGNED_RIGHT_SHIFT |
  3857. //               INSTANCEOF | LESS | GREATER | LESS_EQUAL | GREATER_EQUAL | EQUAL_EQUAL | NOT_EQUAL |
  3858. //               AND | XOR | IOR | AND_AND | OR_OR
  3859. //
  3860. // BinaryOperator --> *_token | /_token | %_token | +_token | -_token | <<_token | >>_token | >>>_token |
  3861. //                    instanceof_token | <_token | >_token | <=_token | >=_token | ==_token | !=_token |
  3862. //                    &_token | ^_token | |_token | &&_token | ||_token
  3863. //
  3864. class AstBinaryExpression : public AstExpression
  3865. {
  3866. public:
  3867.     enum BinaryExpressionTag
  3868.     {
  3869.         NONE,
  3870.         STAR,
  3871.         SLASH,
  3872.         MOD,
  3873.         PLUS,
  3874.         MINUS,
  3875.         LEFT_SHIFT,
  3876.         RIGHT_SHIFT,
  3877.         UNSIGNED_RIGHT_SHIFT,
  3878.         INSTANCEOF,
  3879.         LESS,
  3880.         GREATER,
  3881.         AND,
  3882.         XOR,
  3883.         IOR,
  3884.         AND_AND,
  3885.         OR_OR,
  3886.  
  3887.         LESS_EQUAL,
  3888.         GREATER_EQUAL,
  3889.         EQUAL_EQUAL,
  3890.         NOT_EQUAL,
  3891.  
  3892.         _num_kinds
  3893.     };
  3894.  
  3895.     BinaryExpressionTag binary_tag;
  3896.     AstExpression *left_expression;
  3897.     LexStream::TokenIndex binary_operator_token;
  3898.     AstExpression *right_expression;
  3899.  
  3900.     AstBinaryExpression(BinaryExpressionTag tag_) : binary_tag(tag_)
  3901.     {
  3902.         Ast::kind = Ast::BINARY;
  3903.         Ast::class_tag = Ast::EXPRESSION;
  3904.         Ast::generated = 0;
  3905.         AstExpression::value = NULL;
  3906.         AstExpression::symbol = NULL;
  3907.     }
  3908.  
  3909.     virtual ~AstBinaryExpression();
  3910.  
  3911. #ifdef TEST
  3912.     virtual void Print(LexStream &);
  3913.     virtual void Unparse(Ostream &, LexStream &);
  3914. #endif
  3915.  
  3916.     virtual Ast *Clone(StoragePool *);
  3917.  
  3918.     virtual LexStream::TokenIndex LeftToken()  { return left_expression -> LeftToken(); }
  3919.     virtual LexStream::TokenIndex RightToken() { return right_expression -> RightToken(); }
  3920. };
  3921.  
  3922.  
  3923. //
  3924. // ConditionalExpression --> <CONDITIONAL, Expression, ?_token, Expression, :_token, Expression>
  3925. //
  3926. class AstConditionalExpression : public AstExpression
  3927. {
  3928. public:
  3929.     AstExpression *test_expression;
  3930.     LexStream::TokenIndex question_token;
  3931.     AstExpression *true_expression;
  3932.     LexStream::TokenIndex colon_token;
  3933.     AstExpression *false_expression;
  3934.  
  3935.     AstConditionalExpression()
  3936.     {
  3937.         Ast::kind = Ast::CONDITIONAL;
  3938.         Ast::class_tag = Ast::EXPRESSION;
  3939.         Ast::generated = 0;
  3940.         AstExpression::value = NULL;
  3941.         AstExpression::symbol = NULL;
  3942.     }
  3943.  
  3944.     virtual ~AstConditionalExpression();
  3945.  
  3946. #ifdef TEST
  3947.     virtual void Print(LexStream &);
  3948.     virtual void Unparse(Ostream &, LexStream &);
  3949. #endif
  3950.  
  3951.     virtual Ast *Clone(StoragePool *);
  3952.  
  3953.     virtual LexStream::TokenIndex LeftToken()  { return test_expression -> LeftToken(); }
  3954.     virtual LexStream::TokenIndex RightToken() { return false_expression -> RightToken(); }
  3955. };
  3956.  
  3957.  
  3958. //
  3959. // Assignment --> <ASSIGNMENT, AssignmentTag, LeftHandSide, AssignmentOperator, Expression>
  3960. //
  3961. // AssignmentTag --> EQUAL | STAR_EQUAL | SLASH_EQUAL | MOD_EQUAL | PLUS_EQUAL | MINUS_EQUAL |
  3962. //                   LEFT_SHIFT_EQUAL | RIGHT_SHIFT_EQUAL | UNSIGNED_RIGHT_SHIFT_EQUAL |
  3963. //                   AND_EQUAL | XOR_EQUAL | IOR_EQUAL
  3964. //
  3965. // LeftHandSide --> Name | FieldAccess | ArrayAccess
  3966. //                | <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, Name>
  3967. //                | <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, FieldAccess>
  3968. //                | <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, ArrayAccess>
  3969. //
  3970. // NOTE: that a LeftHandSide appears as a cast node only when the assignment_operator in question
  3971. // is of the form "op=" and the application of the operator requires a casting of the value of the
  3972. // left-hand side.
  3973. //
  3974. // AssignmentOperator --> =_token | *=_token | /=_token | %=_token | +=_token | -=_token |
  3975. //                        <<=_token | >>=_token | >>>=_token | &=_token | ^=_token | |=_token
  3976. //
  3977. class AstAssignmentExpression : public AstExpression
  3978. {
  3979. public:
  3980.     enum AssignmentExpressionTag
  3981.     {
  3982.         NONE,
  3983.         SIMPLE_EQUAL,
  3984.         DEFINITE_EQUAL,
  3985.         STAR_EQUAL,
  3986.         SLASH_EQUAL,
  3987.         MOD_EQUAL,
  3988.         PLUS_EQUAL,
  3989.         MINUS_EQUAL,
  3990.         LEFT_SHIFT_EQUAL,
  3991.         RIGHT_SHIFT_EQUAL,
  3992.         UNSIGNED_RIGHT_SHIFT_EQUAL,
  3993.  
  3994.  
  3995.         AND_EQUAL,
  3996.         XOR_EQUAL,
  3997.         IOR_EQUAL,
  3998.  
  3999.         _num_kinds
  4000.     };
  4001.  
  4002.     //
  4003.     // When the left-hand side of an assignment is a name that refers
  4004.     // to a private field in an enclosing scope, the access method
  4005.     // that gives write-permission to that field is recorded here.
  4006.     //
  4007.     MethodSymbol *write_method;
  4008.  
  4009.     AssignmentExpressionTag assignment_tag;
  4010.     AstExpression *left_hand_side;
  4011.     LexStream::TokenIndex assignment_operator_token;
  4012.     AstExpression *expression;
  4013.  
  4014.     AstAssignmentExpression(AssignmentExpressionTag tag_, LexStream::TokenIndex token_) : write_method(NULL),
  4015.                                                                                           assignment_tag(tag_),
  4016.                                                                                           assignment_operator_token(token_)
  4017.     {
  4018.         Ast::kind = Ast::ASSIGNMENT;
  4019.         Ast::class_tag = Ast::EXPRESSION;
  4020.         Ast::generated = 0;
  4021.         AstExpression::value = NULL;
  4022.         AstExpression::symbol = NULL;
  4023.     }
  4024.  
  4025.     virtual ~AstAssignmentExpression();
  4026.  
  4027.     inline bool SimpleAssignment() { return (assignment_tag == SIMPLE_EQUAL || assignment_tag == DEFINITE_EQUAL); }
  4028.  
  4029. #ifdef TEST
  4030.     virtual void Print(LexStream &);
  4031.     virtual void Unparse(Ostream &, LexStream &);
  4032. #endif
  4033.  
  4034.     virtual Ast *Clone(StoragePool *);
  4035.  
  4036.     virtual LexStream::TokenIndex LeftToken()  { return left_hand_side -> LeftToken(); }
  4037.     virtual LexStream::TokenIndex RightToken() { return expression -> RightToken(); }
  4038. };
  4039.  
  4040.  
  4041. //
  4042. // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  4043. //
  4044. inline bool Ast::IsName()
  4045. {
  4046.     Ast *name = this;
  4047.     for (AstFieldAccess *field_access = name -> FieldAccessCast(); field_access && field_access -> IsNameAccess();
  4048.                                                                    field_access = name -> FieldAccessCast())
  4049.         name = field_access -> base;
  4050.     return (name -> SimpleNameCast() != NULL);
  4051. }
  4052.  
  4053.  
  4054. //
  4055. // Given an Ast tree, check whether or not it is a simple name or
  4056. // a field access consisting only of simple names or keywords.
  4057. //
  4058. inline bool Ast::IsSimpleNameOrFieldAccess()
  4059. {
  4060.     Ast *name = this;
  4061.     for (AstFieldAccess *field_access = name -> FieldAccessCast(); field_access; field_access = name -> FieldAccessCast())
  4062.         name = field_access -> base;
  4063.     return (name -> SimpleNameCast() || name -> TypeExpressionCast());
  4064. }
  4065.  
  4066.  
  4067. //
  4068. // Do we have a simple 'super' expression or a field of the form XXX.super
  4069. //
  4070. inline bool Ast::IsSuperExpression()
  4071. {
  4072.     return (this -> SuperExpressionCast() || (this -> FieldAccessCast() && this -> FieldAccessCast() -> IsSuperAccess()));
  4073.  
  4074. }
  4075.  
  4076. //
  4077. // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  4078. //
  4079. inline bool Ast::IsLeftHandSide()
  4080. {
  4081.     return (this -> SimpleNameCast() || this -> FieldAccessCast() || this -> ArrayAccessCast());
  4082. }
  4083.  
  4084.  
  4085. //
  4086. // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  4087. //
  4088. inline bool Ast::IsGenerated()
  4089. {
  4090.     return (generated == 1);
  4091. }
  4092.  
  4093.  
  4094. //
  4095. // This Storage pool is modeled after the Dynamic arrays. The difference is that
  4096. // instead of a Next() function we have an alloc(size_t) function. The value
  4097. // of the size_t argument represents the size of the object to allocate.
  4098. //
  4099. class StoragePool
  4100. {
  4101. public:
  4102.  
  4103.     typedef void *Cell;
  4104.  
  4105.     inline size_t Blksize() { return (1 << log_blksize); }
  4106.  
  4107. private:
  4108.  
  4109.     Cell **base;
  4110.     size_t base_size;
  4111.     int top,
  4112.         size;
  4113.  
  4114.     size_t log_blksize,
  4115.            base_increment;
  4116.  
  4117.     //
  4118.     // Allocate another block of storage for the storage pool
  4119.     //
  4120.     void AllocateMoreSpace()
  4121.     {
  4122.         //
  4123.         // The variable size always indicates the maximum number of
  4124.         // cells that has been allocated for the storage pool.
  4125.         // Initially, it is set to 0 to indicate that the pool is empty.
  4126.         // The pool of available elements is divided into segments of size
  4127.         // 2**log_blksize each. Each segment is pointed to by a slot in
  4128.         // the array base.
  4129.         //
  4130.         // By dividing size by the size of the segment we obtain the
  4131.         // index for the next segment in base. If base is full, it is
  4132.         // reallocated.
  4133.         //
  4134.         //
  4135.         size_t k = size >> log_blksize; /* which segment? */
  4136.  
  4137.         //
  4138.         // If the base is overflowed, reallocate it and initialize the new elements to NULL.
  4139.         //
  4140.         if (k == base_size)
  4141.         {
  4142.             int old_base_size = base_size;
  4143.             Cell **old_base = base;
  4144.  
  4145.             base_size += base_increment;
  4146.             base = ::new Cell*[base_size];
  4147.  
  4148.             if (old_base != NULL)
  4149.             {
  4150.                 memmove(base, old_base, old_base_size * sizeof(Cell *));
  4151.                 delete [] old_base;
  4152.             }
  4153.             memset(&base[old_base_size], 0, (base_size - old_base_size) * sizeof(Cell *));
  4154.         }
  4155.  
  4156.         //
  4157.         // If the slot "k" does not already contain a segment,
  4158.         // we allocate a new segment and place its adjusted address in
  4159.         // base[k]. The adjustment allows us to index the segment directly,
  4160.         // instead of having to perform a subtraction for each reference.
  4161.         // See operator[] below.
  4162.         //
  4163.         if (base[k] == NULL)
  4164.         {
  4165.             base[k] = ::new Cell[Blksize()];
  4166.             base[k] -= size;
  4167.         }
  4168.  
  4169.         //
  4170.         // Finally, we update SIZE.
  4171.         //
  4172.         size += Blksize();
  4173.  
  4174.         return;
  4175.     }
  4176.  
  4177. public:
  4178.  
  4179.     //
  4180.     // Constructor of a storage pool
  4181.     //
  4182.     StoragePool(size_t num_tokens)
  4183.     {
  4184.         //
  4185.         // Make a guess on the size that will be required for the ast
  4186.         // based on the number of tokens. The ratio for the bodies is
  4187.         // usually 40 to 1. We will double the base to add to account
  4188.         // for the headers
  4189.         //
  4190.         size_t estimate = num_tokens * 10; // recall that each cell is a-byte word. So, 10 * 4 = 40
  4191.  
  4192.         //
  4193.         // Find a block of size 2**log_blksize that is large enough
  4194.         // to satisfy our estimate.
  4195.         //
  4196.         for (log_blksize = 8; (((unsigned) 1 << log_blksize) < estimate) && (log_blksize < 31); log_blksize++)
  4197.             ;
  4198.  
  4199.         //
  4200.         // If the size of the block found is < 1k, allocate a block of size 1k
  4201.         // with one slot to spare, just in case.
  4202.         // If the size is less than 16k, then break it up into equal blocks
  4203.         // of size 1k;
  4204.         // Otherwise, fragment it into pieces of size 16k.
  4205.         //
  4206.         if (log_blksize < 8)
  4207.         {
  4208.             base_increment = 1;
  4209.             log_blksize = 8;
  4210.         }
  4211.         else if (log_blksize < 13)
  4212.         {
  4213.             base_increment = (unsigned) 1 << (log_blksize - 8);
  4214.             log_blksize = 8;
  4215.         }
  4216.         else if (log_blksize < 17)
  4217.         {
  4218.             base_increment = (unsigned) 1 << (log_blksize - 10);
  4219.             log_blksize = 10;
  4220.         }
  4221.         else
  4222.         {
  4223.             base_increment = (unsigned) 1 << (log_blksize - 12); // assume we won't be allocating more than this many blocks.
  4224.             log_blksize = 12;
  4225.         }
  4226.  
  4227.         //
  4228.         // Double the size of the base in order to allocate extra space for the headers
  4229.         // and add a little margin for stuff like extra Cast node and computation of
  4230.         // static expressions that require cloning.
  4231.         //
  4232.         base_increment = (base_increment << 1) + 3;
  4233.  
  4234.         base_size = 0;
  4235.         size = 0;
  4236.         top = 0;
  4237.         base = NULL;
  4238.     }
  4239.  
  4240.     //
  4241.     // Destructor of a storage pool
  4242.     //
  4243.     ~StoragePool()
  4244.     {
  4245.         for (int k = (size >> log_blksize) - 1; k >= 0; k--)
  4246.         {
  4247.             size -= Blksize();
  4248.             base[k] += size;
  4249.             delete [] base[k];
  4250.         }
  4251.  
  4252.         delete [] base;
  4253.     }
  4254.  
  4255.     //
  4256.     // alloc allocates an object of size n in the pool and
  4257.     // returns a pointer to it.
  4258.     //
  4259.     inline void *Alloc(size_t n)
  4260.     {
  4261.         size_t i = top,
  4262.                chunk_size = ((n + sizeof(Cell) - 1) / sizeof(Cell));
  4263.         top += chunk_size;
  4264.         if (top > size)
  4265.         {
  4266.             assert(chunk_size <= Blksize() && "we cannot allocate a chunk of storage that is larger than the block !");
  4267.  
  4268.             i = size;
  4269.             top = size + chunk_size;
  4270.             AllocateMoreSpace();
  4271.         }
  4272.  
  4273.         return ((void *) &(base[i >> log_blksize] [i]));
  4274.     }
  4275.  
  4276.     //
  4277.     // Return length of the amount of storage that has been allocated so far.
  4278.     //
  4279.     inline size_t Length() { return top; }
  4280.  
  4281.     //
  4282.     // This function is used to reset the Storage pool. This action automatically
  4283.     // invalidates all objects that had been allocated in the pool. At least,
  4284.     // YOU should assume it does!!!
  4285.     //
  4286.     inline void Reset(const int n = 0)
  4287.     {
  4288.         if (n < 0 || n > size)
  4289.             assert(false);
  4290.         top = n;
  4291.     }
  4292.  
  4293.     //
  4294.     // This function frees up all dynamic space that
  4295.     // was allocated for this storage pool.
  4296.     //
  4297.     inline void Destroy()
  4298.     {
  4299.         for (int k = (size >> log_blksize) - 1; k >= 0; k--)
  4300.         {
  4301.             size -= Blksize();
  4302.             base[k] += size;
  4303.             delete [] base[k];
  4304.             base[k] = NULL;
  4305.         }
  4306.  
  4307.         delete [] base;
  4308.         base = NULL;
  4309.         base_size = 0;
  4310.  
  4311.         Reset();
  4312.  
  4313.         return;
  4314.     }
  4315.  
  4316.     // ********************************************************************************************** //
  4317.  
  4318.     inline VariableSymbolArray *NewVariableSymbolArray(unsigned size = 0)
  4319.     {
  4320.         return new (Alloc(sizeof(VariableSymbolArray))) VariableSymbolArray((StoragePool *) this, size);
  4321.     }
  4322.  
  4323.     inline AstArray<LexStream::TokenIndex> *NewTokenIndexArray(unsigned size = 0)
  4324.     {
  4325.         return new (Alloc(sizeof(AstArray<LexStream::TokenIndex>))) AstArray<LexStream::TokenIndex>((StoragePool *) this, size);
  4326.     }
  4327.  
  4328.     inline AstArray<Ast *> *NewAstArray(unsigned size = 0)
  4329.     {
  4330.         return new (Alloc(sizeof(AstArray<Ast *>))) AstArray<Ast *>((StoragePool *) this, size);
  4331.     }
  4332.  
  4333.     inline AstArray<CaseElement *> *NewCaseElementArray(unsigned size = 0)
  4334.     {
  4335.         return new (Alloc(sizeof(AstArray<CaseElement *>))) AstArray<CaseElement *>((StoragePool *) this, size);
  4336.     }
  4337.  
  4338.     inline AstListNode *NewListNode()
  4339.     {
  4340.         return new (Alloc(sizeof(AstListNode))) AstListNode();
  4341.     }
  4342.  
  4343.     inline AstBlock *NewBlock()
  4344.     {
  4345.         return new (Alloc(sizeof(AstBlock))) AstBlock((StoragePool *) this);
  4346.     }
  4347.  
  4348.     inline AstPrimitiveType *NewPrimitiveType(Ast::Kind kind, LexStream::TokenIndex token)
  4349.     {
  4350.         return new (Alloc(sizeof(AstPrimitiveType))) AstPrimitiveType(kind, token);
  4351.     }
  4352.  
  4353.     inline AstArrayType *NewArrayType()
  4354.     {
  4355.         return new (Alloc(sizeof(AstArrayType))) AstArrayType((StoragePool *) this);
  4356.     }
  4357.  
  4358.     inline AstSimpleName *NewSimpleName(LexStream::TokenIndex token)
  4359.     {
  4360.         return new (Alloc(sizeof(AstSimpleName))) AstSimpleName(token);
  4361.     }
  4362.  
  4363.     inline AstPackageDeclaration *NewPackageDeclaration()
  4364.     {
  4365.         return new (Alloc(sizeof(AstPackageDeclaration))) AstPackageDeclaration();
  4366.     }
  4367.  
  4368.     inline AstImportDeclaration *NewImportDeclaration()
  4369.     {
  4370.         return new (Alloc(sizeof(AstImportDeclaration))) AstImportDeclaration();
  4371.     }
  4372.  
  4373.     inline AstCompilationUnit *NewCompilationUnit()
  4374.     {
  4375.         return new (Alloc(sizeof(AstCompilationUnit))) AstCompilationUnit((StoragePool *) this);
  4376.     }
  4377.  
  4378.     inline AstModifier *NewModifier(Ast::Kind kind, LexStream::TokenIndex token)
  4379.     {
  4380.         return new (Alloc(sizeof(AstModifier))) AstModifier(kind, token);
  4381.     }
  4382.  
  4383.     inline AstEmptyDeclaration *NewEmptyDeclaration(LexStream::TokenIndex token)
  4384.     {
  4385.         return new (Alloc(sizeof(AstEmptyDeclaration))) AstEmptyDeclaration(token);
  4386.     }
  4387.  
  4388.     inline AstClassBody *NewClassBody()
  4389.     {
  4390.         return new (Alloc(sizeof(AstClassBody))) AstClassBody((StoragePool *) this);
  4391.     }
  4392.  
  4393.     inline AstClassDeclaration *NewClassDeclaration()
  4394.     {
  4395.         return new (Alloc(sizeof(AstClassDeclaration))) AstClassDeclaration((StoragePool *) this);
  4396.     }
  4397.  
  4398.     inline AstArrayInitializer *NewArrayInitializer()
  4399.     {
  4400.         return new (Alloc(sizeof(AstArrayInitializer))) AstArrayInitializer((StoragePool *) this);
  4401.     }
  4402.  
  4403.     inline AstBrackets *NewBrackets(LexStream::TokenIndex left, LexStream::TokenIndex right)
  4404.     {
  4405.         return new (Alloc(sizeof(AstBrackets))) AstBrackets(left, right);
  4406.     }
  4407.  
  4408.     inline AstVariableDeclaratorId *NewVariableDeclaratorId()
  4409.     {
  4410.         return new (Alloc(sizeof(AstVariableDeclaratorId))) AstVariableDeclaratorId((StoragePool *) this);
  4411.     }
  4412.  
  4413.     inline AstVariableDeclarator *NewVariableDeclarator()
  4414.     {
  4415.         return new (Alloc(sizeof(AstVariableDeclarator))) AstVariableDeclarator();
  4416.     }
  4417.  
  4418.     inline AstFieldDeclaration *NewFieldDeclaration()
  4419.     {
  4420.         return new (Alloc(sizeof(AstFieldDeclaration))) AstFieldDeclaration((StoragePool *) this);
  4421.     }
  4422.  
  4423.     inline AstFormalParameter *NewFormalParameter()
  4424.     {
  4425.         return new (Alloc(sizeof(AstFormalParameter))) AstFormalParameter((StoragePool *) this);
  4426.     }
  4427.  
  4428.     inline AstMethodDeclarator *NewMethodDeclarator()
  4429.     {
  4430.         return new (Alloc(sizeof(AstMethodDeclarator))) AstMethodDeclarator((StoragePool *) this);
  4431.     }
  4432.  
  4433.     inline AstMethodDeclaration *NewMethodDeclaration()
  4434.     {
  4435.         return new (Alloc(sizeof(AstMethodDeclaration))) AstMethodDeclaration((StoragePool *) this);
  4436.     }
  4437.  
  4438.     inline AstStaticInitializer *NewStaticInitializer()
  4439.     {
  4440.         return new (Alloc(sizeof(AstStaticInitializer))) AstStaticInitializer();
  4441.     }
  4442.  
  4443.     inline AstThisCall *NewThisCall()
  4444.     {
  4445.         return new (Alloc(sizeof(AstThisCall))) AstThisCall((StoragePool *) this);
  4446.     }
  4447.  
  4448.     inline AstSuperCall *NewSuperCall()
  4449.     {
  4450.         return new (Alloc(sizeof(AstSuperCall))) AstSuperCall((StoragePool *) this);
  4451.     }
  4452.  
  4453.     inline AstConstructorBlock *NewConstructorBlock()
  4454.     {
  4455.         return new (Alloc(sizeof(AstConstructorBlock))) AstConstructorBlock((StoragePool *) this);
  4456.     }
  4457.  
  4458.     inline AstConstructorDeclaration *NewConstructorDeclaration()
  4459.     {
  4460.         return new (Alloc(sizeof(AstConstructorDeclaration))) AstConstructorDeclaration((StoragePool *) this);
  4461.     }
  4462.  
  4463.     inline AstInterfaceDeclaration *NewInterfaceDeclaration()
  4464.     {
  4465.         return new (Alloc(sizeof(AstInterfaceDeclaration))) AstInterfaceDeclaration((StoragePool *) this);
  4466.     }
  4467.  
  4468.     inline AstLocalVariableDeclarationStatement *NewLocalVariableDeclarationStatement()
  4469.     {
  4470.         return new (Alloc(sizeof(AstLocalVariableDeclarationStatement))) AstLocalVariableDeclarationStatement((StoragePool *) this);
  4471.     }
  4472.  
  4473.     inline AstIfStatement *NewIfStatement()
  4474.     {
  4475.         return new (Alloc(sizeof(AstIfStatement))) AstIfStatement((StoragePool *) this);
  4476.     }
  4477.  
  4478.     inline AstEmptyStatement *NewEmptyStatement(LexStream::TokenIndex token)
  4479.     {
  4480.         return new (Alloc(sizeof(AstEmptyStatement))) AstEmptyStatement((StoragePool *) this, token);
  4481.     }
  4482.  
  4483.     inline AstExpressionStatement *NewExpressionStatement()
  4484.     {
  4485.         return new (Alloc(sizeof(AstExpressionStatement))) AstExpressionStatement((StoragePool *) this);
  4486.     }
  4487.  
  4488.     inline AstCaseLabel *NewCaseLabel()
  4489.     {
  4490.         return new (Alloc(sizeof(AstCaseLabel))) AstCaseLabel();
  4491.     }
  4492.  
  4493.     inline AstDefaultLabel *NewDefaultLabel()
  4494.     {
  4495.         return new (Alloc(sizeof(AstDefaultLabel))) AstDefaultLabel();
  4496.     }
  4497.  
  4498.     inline AstSwitchBlockStatement *NewSwitchBlockStatement()
  4499.     {
  4500.         return new (Alloc(sizeof(AstSwitchBlockStatement))) AstSwitchBlockStatement((StoragePool *) this);
  4501.     }
  4502.  
  4503.     inline AstSwitchStatement *NewSwitchStatement()
  4504.     {
  4505.         return new (Alloc(sizeof(AstSwitchStatement))) AstSwitchStatement((StoragePool *) this);
  4506.     }
  4507.  
  4508.     inline AstWhileStatement *NewWhileStatement()
  4509.     {
  4510.         return new (Alloc(sizeof(AstWhileStatement))) AstWhileStatement((StoragePool *) this);
  4511.     }
  4512.  
  4513.     inline AstDoStatement *NewDoStatement()
  4514.     {
  4515.         return new (Alloc(sizeof(AstDoStatement))) AstDoStatement((StoragePool *) this);
  4516.     }
  4517.  
  4518.     inline AstForStatement *NewForStatement()
  4519.     {
  4520.         return new (Alloc(sizeof(AstForStatement))) AstForStatement((StoragePool *) this);
  4521.     }
  4522.  
  4523.     inline AstBreakStatement *NewBreakStatement()
  4524.     {
  4525.         return new (Alloc(sizeof(AstBreakStatement))) AstBreakStatement((StoragePool *) this);
  4526.     }
  4527.  
  4528.     inline AstContinueStatement *NewContinueStatement()
  4529.     {
  4530.         return new (Alloc(sizeof(AstContinueStatement))) AstContinueStatement((StoragePool *) this);
  4531.     }
  4532.  
  4533.     inline AstReturnStatement *NewReturnStatement()
  4534.     {
  4535.         return new (Alloc(sizeof(AstReturnStatement))) AstReturnStatement((StoragePool *) this);
  4536.     }
  4537.  
  4538.     inline AstThrowStatement *NewThrowStatement()
  4539.     {
  4540.         return new (Alloc(sizeof(AstThrowStatement))) AstThrowStatement((StoragePool *) this);
  4541.     }
  4542.  
  4543.     inline AstSynchronizedStatement *NewSynchronizedStatement()
  4544.     {
  4545.         return new (Alloc(sizeof(AstSynchronizedStatement))) AstSynchronizedStatement((StoragePool *) this);
  4546.     }
  4547.  
  4548.     inline AstCatchClause *NewCatchClause()
  4549.     {
  4550.         return new (Alloc(sizeof(AstCatchClause))) AstCatchClause();
  4551.     }
  4552.  
  4553.     inline AstFinallyClause *NewFinallyClause()
  4554.     {
  4555.         return new (Alloc(sizeof(AstFinallyClause))) AstFinallyClause();
  4556.     }
  4557.  
  4558.     inline AstTryStatement *NewTryStatement()
  4559.     {
  4560.         return new (Alloc(sizeof(AstTryStatement))) AstTryStatement((StoragePool *) this);
  4561.     }
  4562.  
  4563.     inline AstIntegerLiteral *NewIntegerLiteral(LexStream::TokenIndex token)
  4564.     {
  4565.         return new (Alloc(sizeof(AstIntegerLiteral))) AstIntegerLiteral(token);
  4566.     }
  4567.  
  4568.     inline AstLongLiteral *NewLongLiteral(LexStream::TokenIndex token)
  4569.     {
  4570.         return new (Alloc(sizeof(AstLongLiteral))) AstLongLiteral(token);
  4571.     }
  4572.  
  4573.     inline AstFloatingPointLiteral *NewFloatingPointLiteral(LexStream::TokenIndex token)
  4574.     {
  4575.         return new (Alloc(sizeof(AstFloatingPointLiteral))) AstFloatingPointLiteral(token);
  4576.     }
  4577.  
  4578.     inline AstDoubleLiteral *NewDoubleLiteral(LexStream::TokenIndex token)
  4579.     {
  4580.         return new (Alloc(sizeof(AstDoubleLiteral))) AstDoubleLiteral(token);
  4581.     }
  4582.  
  4583.     inline AstTrueLiteral *NewTrueLiteral(LexStream::TokenIndex token)
  4584.     {
  4585.         return new (Alloc(sizeof(AstTrueLiteral))) AstTrueLiteral(token);
  4586.     }
  4587.  
  4588.     inline AstFalseLiteral *NewFalseLiteral(LexStream::TokenIndex token)
  4589.     {
  4590.         return new (Alloc(sizeof(AstFalseLiteral))) AstFalseLiteral(token);
  4591.     }
  4592.  
  4593.     inline AstStringLiteral *NewStringLiteral(LexStream::TokenIndex token)
  4594.     {
  4595.         return new (Alloc(sizeof(AstStringLiteral))) AstStringLiteral(token);
  4596.     }
  4597.  
  4598.     inline AstCharacterLiteral *NewCharacterLiteral(LexStream::TokenIndex token)
  4599.     {
  4600.         return new (Alloc(sizeof(AstCharacterLiteral))) AstCharacterLiteral(token);
  4601.     }
  4602.  
  4603.     inline AstNullLiteral *NewNullLiteral(LexStream::TokenIndex token)
  4604.     {
  4605.         return new (Alloc(sizeof(AstNullLiteral))) AstNullLiteral(token);
  4606.     }
  4607.  
  4608.     inline AstThisExpression *NewThisExpression(LexStream::TokenIndex token)
  4609.     {
  4610.         return new (Alloc(sizeof(AstThisExpression))) AstThisExpression(token);
  4611.     }
  4612.  
  4613.     inline AstSuperExpression *NewSuperExpression(LexStream::TokenIndex token)
  4614.     {
  4615.         return new (Alloc(sizeof(AstSuperExpression))) AstSuperExpression(token);
  4616.     }
  4617.  
  4618.     inline AstParenthesizedExpression *NewParenthesizedExpression()
  4619.     {
  4620.         return new (Alloc(sizeof(AstParenthesizedExpression))) AstParenthesizedExpression();
  4621.     }
  4622.  
  4623.     inline AstTypeExpression *NewTypeExpression(Ast *type)
  4624.     {
  4625.         return new (Alloc(sizeof(AstTypeExpression))) AstTypeExpression(type);
  4626.     }
  4627.  
  4628.     inline AstClassInstanceCreationExpression *NewClassInstanceCreationExpression()
  4629.     {
  4630.         return new (Alloc(sizeof(AstClassInstanceCreationExpression))) AstClassInstanceCreationExpression((StoragePool *) this);
  4631.     }
  4632.  
  4633.     inline AstDimExpr *NewDimExpr()
  4634.     {
  4635.         return new (Alloc(sizeof(AstDimExpr))) AstDimExpr();
  4636.     }
  4637.  
  4638.     inline AstArrayCreationExpression *NewArrayCreationExpression()
  4639.     {
  4640.         return new (Alloc(sizeof(AstArrayCreationExpression))) AstArrayCreationExpression((StoragePool *) this);
  4641.     }
  4642.  
  4643.     inline AstFieldAccess *NewFieldAccess(AstFieldAccess::FieldAccessTag tag = AstFieldAccess::NONE)
  4644.     {
  4645.         return new (Alloc(sizeof(AstFieldAccess))) AstFieldAccess(tag);
  4646.     }
  4647.  
  4648.     inline AstMethodInvocation *NewMethodInvocation()
  4649.     {
  4650.         return new (Alloc(sizeof(AstMethodInvocation))) AstMethodInvocation((StoragePool *) this);
  4651.     }
  4652.  
  4653.     inline AstArrayAccess *NewArrayAccess()
  4654.     {
  4655.         return new (Alloc(sizeof(AstArrayAccess))) AstArrayAccess();
  4656.     }
  4657.  
  4658.     inline AstPostUnaryExpression *NewPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)
  4659.     {
  4660.         return new (Alloc(sizeof(AstPostUnaryExpression))) AstPostUnaryExpression(tag);
  4661.     }
  4662.  
  4663.     inline AstPreUnaryExpression *NewPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)
  4664.     {
  4665.         return new (Alloc(sizeof(AstPreUnaryExpression))) AstPreUnaryExpression(tag);
  4666.     }
  4667.  
  4668.     inline AstCastExpression *NewCastExpression()
  4669.     {
  4670.         return new (Alloc(sizeof(AstCastExpression))) AstCastExpression((StoragePool *) this);
  4671.     }
  4672.  
  4673.     inline AstBinaryExpression *NewBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)
  4674.     {
  4675.         return new (Alloc(sizeof(AstBinaryExpression))) AstBinaryExpression(tag);
  4676.     }
  4677.  
  4678.     inline AstConditionalExpression *NewConditionalExpression()
  4679.     {
  4680.         return new (Alloc(sizeof(AstConditionalExpression))) AstConditionalExpression();
  4681.     }
  4682.  
  4683.     inline AstAssignmentExpression *NewAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag, LexStream::TokenIndex token)
  4684.     {
  4685.         return new (Alloc(sizeof(AstAssignmentExpression))) AstAssignmentExpression(tag, token);
  4686.     }
  4687.  
  4688.     // ********************************************************************************************** //
  4689.  
  4690.     //
  4691.     // Note that CaseElement nodes are always generated.
  4692.     // Since they are not Ast nodes they do not need to
  4693.     // be marked.
  4694.     //
  4695.     inline CaseElement *GenCaseElement()
  4696.     {
  4697.         return new (Alloc(sizeof(CaseElement))) CaseElement();
  4698.     }
  4699.  
  4700.     inline AstBlock *GenBlock()
  4701.     {
  4702.         AstBlock *p = NewBlock();
  4703.         p -> generated = 1;
  4704.         return p;
  4705.     }
  4706.  
  4707.     inline AstPrimitiveType *GenPrimitiveType(Ast::Kind kind, LexStream::TokenIndex token)
  4708.     {
  4709.         AstPrimitiveType *p = NewPrimitiveType(kind, token);
  4710.         p -> generated = 1;
  4711.         return p;
  4712.     }
  4713.  
  4714.     inline AstArrayType *GenArrayType()
  4715.     {
  4716.         AstArrayType *p = NewArrayType();
  4717.         p -> generated = 1;
  4718.         return p;
  4719.     }
  4720.  
  4721.     inline AstSimpleName *GenSimpleName(LexStream::TokenIndex token)
  4722.     {
  4723.         AstSimpleName *p = NewSimpleName(token);
  4724.         p -> generated = 1;
  4725.         return p;
  4726.     }
  4727.  
  4728.     inline AstPackageDeclaration *GenPackageDeclaration()
  4729.     {
  4730.         AstPackageDeclaration *p = NewPackageDeclaration();
  4731.         p -> generated = 1;
  4732.         return p;
  4733.     }
  4734.  
  4735.     inline AstImportDeclaration *GenImportDeclaration()
  4736.     {
  4737.         AstImportDeclaration *p = NewImportDeclaration();
  4738.         p -> generated = 1;
  4739.         return p;
  4740.     }
  4741.  
  4742.     inline AstCompilationUnit *GenCompilationUnit()
  4743.     {
  4744.         AstCompilationUnit *p = NewCompilationUnit();
  4745.         p -> generated = 1;
  4746.         return p;
  4747.     }
  4748.  
  4749.     inline AstModifier *GenModifier(Ast::Kind kind, LexStream::TokenIndex token)
  4750.     {
  4751.         AstModifier *p = NewModifier(kind, token);
  4752.         p -> generated = 1;
  4753.         return p;
  4754.     }
  4755.  
  4756.     inline AstEmptyDeclaration *GenEmptyDeclaration(LexStream::TokenIndex token)
  4757.     {
  4758.         AstEmptyDeclaration *p = NewEmptyDeclaration(token);
  4759.         p -> generated = 1;
  4760.         return p;
  4761.     }
  4762.  
  4763.     inline AstClassBody *GenClassBody()
  4764.     {
  4765.         AstClassBody *p = NewClassBody();
  4766.         p -> generated = 1;
  4767.         return p;
  4768.     }
  4769.  
  4770.     inline AstClassDeclaration *GenClassDeclaration()
  4771.     {
  4772.         AstClassDeclaration *p = NewClassDeclaration();
  4773.         p -> generated = 1;
  4774.         return p;
  4775.     }
  4776.  
  4777.     inline AstArrayInitializer *GenArrayInitializer()
  4778.     {
  4779.         AstArrayInitializer *p = NewArrayInitializer();
  4780.         p -> generated = 1;
  4781.         return p;
  4782.     }
  4783.  
  4784.     inline AstBrackets *GenBrackets(LexStream::TokenIndex left, LexStream::TokenIndex right)
  4785.     {
  4786.         AstBrackets *p = NewBrackets(left, right);
  4787.         p -> generated = 1;
  4788.         return p;
  4789.     }
  4790.  
  4791.     inline AstVariableDeclaratorId *GenVariableDeclaratorId()
  4792.     {
  4793.         AstVariableDeclaratorId *p = NewVariableDeclaratorId();
  4794.         p -> generated = 1;
  4795.         return p;
  4796.     }
  4797.  
  4798.     inline AstVariableDeclarator *GenVariableDeclarator()
  4799.     {
  4800.         AstVariableDeclarator *p = NewVariableDeclarator();
  4801.         p -> generated = 1;
  4802.         return p;
  4803.     }
  4804.  
  4805.     inline AstFieldDeclaration *GenFieldDeclaration()
  4806.     {
  4807.         AstFieldDeclaration *p = NewFieldDeclaration();
  4808.         p -> generated = 1;
  4809.         return p;
  4810.     }
  4811.  
  4812.     inline AstFormalParameter *GenFormalParameter()
  4813.     {
  4814.         AstFormalParameter *p = NewFormalParameter();
  4815.         p -> generated = 1;
  4816.         return p;
  4817.     }
  4818.  
  4819.     inline AstMethodDeclarator *GenMethodDeclarator()
  4820.     {
  4821.         AstMethodDeclarator *p = NewMethodDeclarator();
  4822.         p -> generated = 1;
  4823.         return p;
  4824.     }
  4825.  
  4826.     inline AstMethodDeclaration *GenMethodDeclaration()
  4827.     {
  4828.         AstMethodDeclaration *p = NewMethodDeclaration();
  4829.         p -> generated = 1;
  4830.         return p;
  4831.     }
  4832.  
  4833.     inline AstStaticInitializer *GenStaticInitializer()
  4834.     {
  4835.         AstStaticInitializer *p = NewStaticInitializer();
  4836.         p -> generated = 1;
  4837.         return p;
  4838.     }
  4839.  
  4840.     inline AstThisCall *GenThisCall()
  4841.     {
  4842.         AstThisCall *p = NewThisCall();
  4843.         p -> generated = 1;
  4844.         return p;
  4845.     }
  4846.  
  4847.     inline AstSuperCall *GenSuperCall()
  4848.     {
  4849.         AstSuperCall *p = NewSuperCall();
  4850.         p -> generated = 1;
  4851.         return p;
  4852.     }
  4853.  
  4854.     inline AstConstructorBlock *GenConstructorBlock()
  4855.     {
  4856.         AstConstructorBlock *p = NewConstructorBlock();
  4857.         p -> generated = 1;
  4858.         return p;
  4859.     }
  4860.  
  4861.     inline AstConstructorDeclaration *GenConstructorDeclaration()
  4862.     {
  4863.         AstConstructorDeclaration *p = NewConstructorDeclaration();
  4864.         p -> generated = 1;
  4865.         return p;
  4866.     }
  4867.  
  4868.     inline AstInterfaceDeclaration *GenInterfaceDeclaration()
  4869.     {
  4870.         AstInterfaceDeclaration *p = NewInterfaceDeclaration();
  4871.         p -> generated = 1;
  4872.         return p;
  4873.     }
  4874.  
  4875.     inline AstLocalVariableDeclarationStatement *GenLocalVariableDeclarationStatement()
  4876.     {
  4877.         AstLocalVariableDeclarationStatement *p = NewLocalVariableDeclarationStatement();
  4878.         p -> generated = 1;
  4879.         return p;
  4880.     }
  4881.  
  4882.     inline AstIfStatement *GenIfStatement()
  4883.     {
  4884.         AstIfStatement *p = NewIfStatement();
  4885.         p -> generated = 1;
  4886.         return p;
  4887.     }
  4888.  
  4889.     inline AstEmptyStatement *GenEmptyStatement(LexStream::TokenIndex token)
  4890.     {
  4891.         AstEmptyStatement *p = NewEmptyStatement(token);
  4892.         p -> generated = 1;
  4893.         return p;
  4894.     }
  4895.  
  4896.     inline AstExpressionStatement *GenExpressionStatement()
  4897.     {
  4898.         AstExpressionStatement *p = NewExpressionStatement();
  4899.         p -> generated = 1;
  4900.         return p;
  4901.     }
  4902.  
  4903.     inline AstCaseLabel *GenCaseLabel()
  4904.     {
  4905.         AstCaseLabel *p = NewCaseLabel();
  4906.         p -> generated = 1;
  4907.         return p;
  4908.     }
  4909.  
  4910.     inline AstDefaultLabel *GenDefaultLabel()
  4911.     {
  4912.         AstDefaultLabel *p = NewDefaultLabel();
  4913.         p -> generated = 1;
  4914.         return p;
  4915.     }
  4916.  
  4917.     inline AstSwitchBlockStatement *GenSwitchBlockStatement()
  4918.     {
  4919.         AstSwitchBlockStatement *p = NewSwitchBlockStatement();
  4920.         p -> generated = 1;
  4921.         return p;
  4922.     }
  4923.  
  4924.     inline AstSwitchStatement *GenSwitchStatement()
  4925.     {
  4926.         AstSwitchStatement *p = NewSwitchStatement();
  4927.         p -> generated = 1;
  4928.         return p;
  4929.     }
  4930.  
  4931.     inline AstWhileStatement *GenWhileStatement()
  4932.     {
  4933.         AstWhileStatement *p = NewWhileStatement();
  4934.         p -> generated = 1;
  4935.         return p;
  4936.     }
  4937.  
  4938.     inline AstDoStatement *GenDoStatement()
  4939.     {
  4940.         AstDoStatement *p = NewDoStatement();
  4941.         p -> generated = 1;
  4942.         return p;
  4943.     }
  4944.  
  4945.     inline AstForStatement *GenForStatement()
  4946.     {
  4947.         AstForStatement *p = NewForStatement();
  4948.         p -> generated = 1;
  4949.         return p;
  4950.     }
  4951.  
  4952.     inline AstBreakStatement *GenBreakStatement()
  4953.     {
  4954.         AstBreakStatement *p = NewBreakStatement();
  4955.         p -> generated = 1;
  4956.         return p;
  4957.     }
  4958.  
  4959.     inline AstContinueStatement *GenContinueStatement()
  4960.     {
  4961.         AstContinueStatement *p = NewContinueStatement();
  4962.         p -> generated = 1;
  4963.         return p;
  4964.     }
  4965.  
  4966.     inline AstReturnStatement *GenReturnStatement()
  4967.     {
  4968.         AstReturnStatement *p = NewReturnStatement();
  4969.         p -> generated = 1;
  4970.         return p;
  4971.     }
  4972.  
  4973.     inline AstThrowStatement *GenThrowStatement()
  4974.     {
  4975.         AstThrowStatement *p = NewThrowStatement();
  4976.         p -> generated = 1;
  4977.         return p;
  4978.     }
  4979.  
  4980.     inline AstSynchronizedStatement *GenSynchronizedStatement()
  4981.     {
  4982.         AstSynchronizedStatement *p = NewSynchronizedStatement();
  4983.         p -> generated = 1;
  4984.         return p;
  4985.     }
  4986.  
  4987.     inline AstCatchClause *GenCatchClause()
  4988.     {
  4989.         AstCatchClause *p = NewCatchClause();
  4990.         p -> generated = 1;
  4991.         return p;
  4992.     }
  4993.  
  4994.     inline AstFinallyClause *GenFinallyClause()
  4995.     {
  4996.         AstFinallyClause *p = NewFinallyClause();
  4997.         p -> generated = 1;
  4998.         return p;
  4999.     }
  5000.  
  5001.     inline AstTryStatement *GenTryStatement()
  5002.     {
  5003.         AstTryStatement *p = NewTryStatement();
  5004.         p -> generated = 1;
  5005.         return p;
  5006.     }
  5007.  
  5008.     inline AstIntegerLiteral *GenIntegerLiteral(LexStream::TokenIndex token)
  5009.     {
  5010.         AstIntegerLiteral *p = NewIntegerLiteral(token);
  5011.         p -> generated = 1;
  5012.         return p;
  5013.     }
  5014.  
  5015.     inline AstLongLiteral *GenLongLiteral(LexStream::TokenIndex token)
  5016.     {
  5017.         AstLongLiteral *p = NewLongLiteral(token);
  5018.         p -> generated = 1;
  5019.         return p;
  5020.     }
  5021.  
  5022.     inline AstFloatingPointLiteral *GenFloatingPointLiteral(LexStream::TokenIndex token)
  5023.     {
  5024.         AstFloatingPointLiteral *p = NewFloatingPointLiteral(token);
  5025.         p -> generated = 1;
  5026.         return p;
  5027.     }
  5028.  
  5029.     inline AstDoubleLiteral *GenDoubleLiteral(LexStream::TokenIndex token)
  5030.     {
  5031.         AstDoubleLiteral *p = NewDoubleLiteral(token);
  5032.         p -> generated = 1;
  5033.         return p;
  5034.     }
  5035.  
  5036.     inline AstTrueLiteral *GenTrueLiteral(LexStream::TokenIndex token)
  5037.     {
  5038.         AstTrueLiteral *p = NewTrueLiteral(token);
  5039.         p -> generated = 1;
  5040.         return p;
  5041.     }
  5042.  
  5043.     inline AstFalseLiteral *GenFalseLiteral(LexStream::TokenIndex token)
  5044.     {
  5045.         AstFalseLiteral *p = NewFalseLiteral(token);
  5046.         p -> generated = 1;
  5047.         return p;
  5048.     }
  5049.  
  5050.     inline AstStringLiteral *GenStringLiteral(LexStream::TokenIndex token)
  5051.     {
  5052.         AstStringLiteral *p = NewStringLiteral(token);
  5053.         p -> generated = 1;
  5054.         return p;
  5055.     }
  5056.  
  5057.     inline AstCharacterLiteral *GenCharacterLiteral(LexStream::TokenIndex token)
  5058.     {
  5059.         AstCharacterLiteral *p = NewCharacterLiteral(token);
  5060.         p -> generated = 1;
  5061.         return p;
  5062.     }
  5063.  
  5064.     inline AstNullLiteral *GenNullLiteral(LexStream::TokenIndex token)
  5065.     {
  5066.         AstNullLiteral *p = NewNullLiteral(token);
  5067.         p -> generated = 1;
  5068.         return p;
  5069.     }
  5070.  
  5071.     inline AstThisExpression *GenThisExpression(LexStream::TokenIndex token)
  5072.     {
  5073.         AstThisExpression *p = NewThisExpression(token);
  5074.         p -> generated = 1;
  5075.         return p;
  5076.     }
  5077.  
  5078.     inline AstSuperExpression *GenSuperExpression(LexStream::TokenIndex token)
  5079.     {
  5080.         AstSuperExpression *p = NewSuperExpression(token);
  5081.         p -> generated = 1;
  5082.         return p;
  5083.     }
  5084.  
  5085.     inline AstParenthesizedExpression *GenParenthesizedExpression()
  5086.     {
  5087.         AstParenthesizedExpression *p = NewParenthesizedExpression();
  5088.         p -> generated = 1;
  5089.         return p;
  5090.     }
  5091.  
  5092.     inline AstTypeExpression *GenTypeExpression(Ast *type)
  5093.     {
  5094.         AstTypeExpression *p = NewTypeExpression(type);
  5095.         p -> generated = 1;
  5096.         return p;
  5097.     }
  5098.  
  5099.     inline AstClassInstanceCreationExpression *GenClassInstanceCreationExpression()
  5100.     {
  5101.         AstClassInstanceCreationExpression *p = NewClassInstanceCreationExpression();
  5102.         p -> generated = 1;
  5103.         return p;
  5104.     }
  5105.  
  5106.     inline AstDimExpr *GenDimExpr()
  5107.     {
  5108.         AstDimExpr *p = NewDimExpr();
  5109.         p -> generated = 1;
  5110.         return p;
  5111.     }
  5112.  
  5113.     inline AstArrayCreationExpression *GenArrayCreationExpression()
  5114.     {
  5115.         AstArrayCreationExpression *p = NewArrayCreationExpression();
  5116.         p -> generated = 1;
  5117.         return p;
  5118.     }
  5119.  
  5120.     inline AstFieldAccess *GenFieldAccess(AstFieldAccess::FieldAccessTag tag = AstFieldAccess::NONE)
  5121.     {
  5122.         AstFieldAccess *p = NewFieldAccess(tag);
  5123.         p -> generated = 1;
  5124.         return p;
  5125.     }
  5126.  
  5127.     inline AstMethodInvocation *GenMethodInvocation()
  5128.     {
  5129.         AstMethodInvocation *p = NewMethodInvocation();
  5130.         p -> generated = 1;
  5131.         return p;
  5132.     }
  5133.  
  5134.     inline AstArrayAccess *GenArrayAccess()
  5135.     {
  5136.         AstArrayAccess *p = NewArrayAccess();
  5137.         p -> generated = 1;
  5138.         return p;
  5139.     }
  5140.  
  5141.     inline AstPostUnaryExpression *GenPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)
  5142.     {
  5143.         AstPostUnaryExpression *p = NewPostUnaryExpression(tag);
  5144.         p -> generated = 1;
  5145.         return p;
  5146.     }
  5147.  
  5148.     inline AstPreUnaryExpression *GenPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)
  5149.     {
  5150.         AstPreUnaryExpression *p = NewPreUnaryExpression(tag);
  5151.         p -> generated = 1;
  5152.         return p;
  5153.     }
  5154.  
  5155.     inline AstCastExpression *GenCastExpression()
  5156.     {
  5157.         AstCastExpression *p = NewCastExpression();
  5158.         p -> generated = 1;
  5159.         return p;
  5160.     }
  5161.  
  5162.     inline AstBinaryExpression *GenBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)
  5163.     {
  5164.         AstBinaryExpression *p = NewBinaryExpression(tag);
  5165.         p -> generated = 1;
  5166.         return p;
  5167.     }
  5168.  
  5169.     inline AstConditionalExpression *GenConditionalExpression()
  5170.     {
  5171.         AstConditionalExpression *p = NewConditionalExpression();
  5172.         p -> generated = 1;
  5173.         return p;
  5174.     }
  5175.  
  5176.     inline AstAssignmentExpression *GenAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag, LexStream::TokenIndex token)
  5177.     {
  5178.         AstAssignmentExpression *p = NewAssignmentExpression(tag, token);
  5179.         p -> generated = 1;
  5180.         return p;
  5181.     }
  5182.  
  5183.     // ********************************************************************************************** //
  5184.  
  5185.     //
  5186.     // Return the total size of temporary space allocated.
  5187.     //
  5188.     size_t SpaceAllocated(void)
  5189.     {
  5190.         return ((base_size * sizeof(Cell **)) + (size * sizeof(Cell)));
  5191.     }
  5192.  
  5193.     //
  5194.     // Return the total size of temporary space used.
  5195.     //
  5196.     size_t SpaceUsed(void)
  5197.     {
  5198.         return (((size >> log_blksize) * sizeof(Cell **)) + (top * sizeof(Cell)));
  5199.     }
  5200. };
  5201.  
  5202. inline void AstClassBody::AllocateInstanceVariables(int estimate)
  5203. {
  5204.     if (! instance_variables)
  5205.         instance_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray(estimate);
  5206. }
  5207.  
  5208. inline void AstClassBody::AddInstanceVariable(AstFieldDeclaration *field_declaration)
  5209. {
  5210.     if (! instance_variables)
  5211.         instance_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray();
  5212.     instance_variables -> Next() = field_declaration;
  5213. }
  5214.  
  5215. inline void AstClassBody::AllocateClassVariables(int estimate)
  5216. {
  5217.     if (! class_variables)
  5218.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray(estimate);
  5219. }
  5220.  
  5221. inline void AstClassBody::AddClassVariable(AstFieldDeclaration *field_declaration)
  5222. {
  5223.     if (! class_variables)
  5224.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray();
  5225.     class_variables -> Next() = field_declaration;
  5226. }
  5227.  
  5228. inline void AstClassBody::AllocateMethods(int estimate)
  5229. {
  5230.     if (! methods)
  5231.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray(estimate);
  5232. }
  5233.  
  5234. inline void AstClassBody::AddMethod(AstMethodDeclaration *method_declaration)
  5235. {
  5236.     if (! methods)
  5237.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray();
  5238.     methods -> Next() = method_declaration;
  5239. }
  5240.  
  5241. inline void AstClassBody::AllocateBlocks(int estimate)
  5242. {
  5243.     if (! blocks)
  5244.         blocks = (AstArray<AstBlock *> *) pool -> NewAstArray(estimate);
  5245. }
  5246.  
  5247. inline void AstClassBody::AddBlock(AstBlock *block)
  5248. {
  5249.     if (! blocks)
  5250.         blocks = (AstArray<AstBlock *> *) pool -> NewAstArray();
  5251.     blocks -> Next() = block;
  5252. }
  5253.  
  5254. inline void AstClassBody::AllocateNestedInterfaces(int estimate)
  5255. {
  5256.     if (! inner_interfaces)
  5257.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray(estimate);
  5258. }
  5259.  
  5260. inline void AstClassBody::AddNestedInterface(AstInterfaceDeclaration *interface_declaration)
  5261. {
  5262.     if (! inner_interfaces)
  5263.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray();
  5264.     inner_interfaces -> Next() = interface_declaration;
  5265. }
  5266.  
  5267. inline void AstClassBody::AllocateNestedClasses(int estimate)
  5268. {
  5269.     if (! inner_classes)
  5270.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray(estimate);
  5271. }
  5272.  
  5273. inline void AstClassBody::AddNestedClass(AstClassDeclaration *class_declaration)
  5274. {
  5275.     if (! inner_classes)
  5276.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray();
  5277.     inner_classes -> Next() = class_declaration;
  5278. }
  5279.  
  5280. inline void AstClassBody::AllocateStaticInitializers(int estimate)
  5281. {
  5282.     if (! static_initializers)
  5283.         static_initializers = (AstArray<AstStaticInitializer *> *) pool -> NewAstArray(estimate);
  5284. }
  5285.  
  5286. inline void AstClassBody::AddStaticInitializer(AstStaticInitializer *static_initializer)
  5287. {
  5288.     if (! static_initializers)
  5289.         static_initializers = (AstArray<AstStaticInitializer *> *) pool -> NewAstArray();
  5290.     static_initializers -> Next() = static_initializer;
  5291. }
  5292.  
  5293. inline void AstClassBody::AllocateConstructors(int estimate)
  5294. {
  5295.     if (! constructors)
  5296.         constructors = (AstArray<AstConstructorDeclaration *> *) pool -> NewAstArray(estimate);
  5297. }
  5298.  
  5299. inline void AstClassBody::AddConstructor(AstConstructorDeclaration *constructor_declaration)
  5300. {
  5301.     if (! constructors)
  5302.         constructors = (AstArray<AstConstructorDeclaration *> *) pool -> NewAstArray();
  5303.     constructors -> Next() = constructor_declaration;
  5304. }
  5305.  
  5306. inline void AstClassBody::AllocateEmptyDeclarations(int estimate)
  5307. {
  5308.     if (! empty_declarations)
  5309.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray(estimate);
  5310. }
  5311.  
  5312. inline void AstClassBody::AddEmptyDeclaration(AstEmptyDeclaration *empty_declaration)
  5313. {
  5314.     if (! empty_declarations)
  5315.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray();
  5316.     empty_declarations -> Next() = empty_declaration;
  5317. }
  5318.  
  5319. inline void AstInterfaceDeclaration::AllocateNestedInterfaces(int estimate)
  5320. {
  5321.     if (! inner_interfaces)
  5322.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray(estimate);
  5323. }
  5324.  
  5325. inline void AstInterfaceDeclaration::AddNestedInterface(AstInterfaceDeclaration *interface_declaration)
  5326. {
  5327.     if (! inner_interfaces)
  5328.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray();
  5329.     inner_interfaces -> Next() = interface_declaration;
  5330. }
  5331.  
  5332. inline void AstInterfaceDeclaration::AllocateNestedClasses(int estimate)
  5333. {
  5334.     if (! inner_classes)
  5335.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray(estimate);
  5336. }
  5337.  
  5338. inline void AstInterfaceDeclaration::AddNestedClass(AstClassDeclaration *class_declaration)
  5339. {
  5340.     if (! inner_classes)
  5341.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray();
  5342.     inner_classes -> Next() = class_declaration;
  5343. }
  5344.  
  5345. inline void AstInterfaceDeclaration::AllocateMethods(int estimate)
  5346. {
  5347.     if (! methods)
  5348.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray(estimate);
  5349. }
  5350.  
  5351. inline void AstInterfaceDeclaration::AddMethod(AstMethodDeclaration *method_declaration)
  5352. {
  5353.     if (! methods)
  5354.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray();
  5355.     methods -> Next() = method_declaration;
  5356. }
  5357.  
  5358. inline void AstInterfaceDeclaration::AllocateClassVariables(int estimate)
  5359. {
  5360.     if (! class_variables)
  5361.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray(estimate);
  5362. }
  5363.  
  5364. inline void AstInterfaceDeclaration::AddClassVariable(AstFieldDeclaration *field_declaration)
  5365. {
  5366.     if (! class_variables)
  5367.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray();
  5368.     class_variables -> Next() = field_declaration;
  5369. }
  5370.  
  5371. inline void AstInterfaceDeclaration::AllocateEmptyDeclarations(int estimate)
  5372. {
  5373.     if (! empty_declarations)
  5374.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray(estimate);
  5375. }
  5376.  
  5377. inline void AstInterfaceDeclaration::AddEmptyDeclaration(AstEmptyDeclaration *empty_declaration)
  5378. {
  5379.     if (! empty_declarations)
  5380.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray();
  5381.     empty_declarations -> Next() = empty_declaration;
  5382. }
  5383.  
  5384. inline void AstClassDeclaration::AllocateClassModifiers(int estimate)
  5385. {
  5386.     if (! class_modifiers)
  5387.         class_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5388. }
  5389.  
  5390. inline void AstClassDeclaration::AddClassModifier(AstModifier *class_modifier)
  5391. {
  5392.     if (! class_modifiers)
  5393.         AllocateClassModifiers(4); // there are only 10 modifiers.
  5394.     class_modifiers -> Next() = class_modifier;
  5395. }
  5396.  
  5397. inline void AstFieldDeclaration::AllocateVariableModifiers(int estimate)
  5398. {
  5399.     if (! variable_modifiers)
  5400.         variable_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5401. }
  5402.  
  5403. inline void AstFieldDeclaration::AddVariableModifier(AstModifier *variable_modifier)
  5404. {
  5405.     if (! variable_modifiers)
  5406.         AllocateVariableModifiers(4); // there are only 10 modifiers.
  5407.     variable_modifiers -> Next() = variable_modifier;
  5408. }
  5409.  
  5410. inline void AstFormalParameter::AllocateParameterModifiers(int estimate)
  5411. {
  5412.     if (! parameter_modifiers)
  5413.         parameter_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5414. }
  5415.  
  5416. inline void AstFormalParameter::AddParameterModifier(AstModifier *parameter_modifier)
  5417. {
  5418.     if (! parameter_modifiers)
  5419.         AllocateParameterModifiers(4); // there are only 10 modifiers.
  5420.     parameter_modifiers -> Next() = parameter_modifier;
  5421. }
  5422.  
  5423. inline void AstMethodDeclaration::AllocateMethodModifiers(int estimate)
  5424. {
  5425.     if (! method_modifiers)
  5426.         method_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5427. }
  5428.  
  5429. inline void AstMethodDeclaration::AddMethodModifier(AstModifier *method_modifier)
  5430. {
  5431.     if (! method_modifiers)
  5432.         AllocateMethodModifiers(4); // there are only 10 modifiers.
  5433.     method_modifiers -> Next() = method_modifier;
  5434. }
  5435.  
  5436. inline void AstConstructorDeclaration::AllocateConstructorModifiers(int estimate)
  5437. {
  5438.     if (! constructor_modifiers)
  5439.         constructor_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5440. }
  5441.  
  5442. inline void AstConstructorDeclaration::AddConstructorModifier(AstModifier *constructor_modifier)
  5443. {
  5444.     if (! constructor_modifiers)
  5445.         AllocateConstructorModifiers(4); // there are only 10 modifiers.
  5446.     constructor_modifiers -> Next() = constructor_modifier;
  5447. }
  5448.  
  5449. inline void AstInterfaceDeclaration::AllocateInterfaceModifiers(int estimate)
  5450. {
  5451.     if (! interface_modifiers)
  5452.         interface_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5453. }
  5454.  
  5455. inline void AstInterfaceDeclaration::AddInterfaceModifier(AstModifier *interface_modifier)
  5456. {
  5457.     if (! interface_modifiers)
  5458.         AllocateInterfaceModifiers(4); // there are only 10 modifiers.
  5459.     interface_modifiers -> Next() = interface_modifier;
  5460. }
  5461.  
  5462. inline void AstLocalVariableDeclarationStatement::AllocateLocalModifiers(int estimate)
  5463. {
  5464.     if (! local_modifiers)
  5465.         local_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5466. }
  5467.  
  5468. inline void AstLocalVariableDeclarationStatement::AddLocalModifier(AstModifier *local_modifier)
  5469. {
  5470.     if (! local_modifiers)
  5471.         AllocateLocalModifiers(4); // there are only 10 modifiers.
  5472.     local_modifiers -> Next() = local_modifier;
  5473. }
  5474.  
  5475. inline void AstBlock::AllocateBlockStatements(int estimate)
  5476. {
  5477.     if (! block_statements)
  5478.         block_statements = pool -> NewAstArray(estimate);
  5479. }
  5480.  
  5481. inline void AstBlock::AddStatement(Ast *statement)
  5482. {
  5483.     if (! block_statements)
  5484.         AllocateBlockStatements();
  5485.     block_statements -> Next() = statement;
  5486. }
  5487.  
  5488. inline void AstBlock::AllocateLabels(int estimate)
  5489. {
  5490.     if (! labels)
  5491.         labels = pool -> NewTokenIndexArray(estimate);
  5492. }
  5493.  
  5494. inline void AstBlock::AddLabel(LexStream::TokenIndex label_token_index)
  5495. {
  5496.     if (! labels)
  5497.         AllocateLabels();
  5498.     labels -> Next() = label_token_index;
  5499. }
  5500.  
  5501. inline void AstBlock::AllocateLocallyDefinedVariables(int estimate)
  5502. {
  5503.     if (! locally_defined_variables)
  5504.         locally_defined_variables = pool -> NewVariableSymbolArray(estimate);
  5505. }
  5506.  
  5507. inline void AstBlock::AddLocallyDefinedVariable(VariableSymbol *variable_symbol)
  5508. {
  5509.     if (! locally_defined_variables)
  5510.         AllocateLocallyDefinedVariables();
  5511.     locally_defined_variables -> Next() = variable_symbol;
  5512. }
  5513.  
  5514. inline void AstBlock::TransferLocallyDefinedVariablesTo(AstSwitchBlockStatement *switch_block_statement)
  5515. {
  5516.     switch_block_statement -> locally_defined_variables = this -> locally_defined_variables;
  5517.     this -> locally_defined_variables = NULL;
  5518. }
  5519.  
  5520. inline void AstStatement::AllocateDefinedVariables(int estimate)
  5521. {
  5522.     if (! defined_variables)
  5523.         defined_variables = pool -> NewVariableSymbolArray(estimate);
  5524. }
  5525.  
  5526. inline void AstStatement::AddDefinedVariable(VariableSymbol *variable_symbol)
  5527. {
  5528.     if (! defined_variables)
  5529.         AllocateDefinedVariables();
  5530.     defined_variables -> Next() = variable_symbol;
  5531. }
  5532.  
  5533. inline void AstSwitchBlockStatement::AllocateBlockStatements(int estimate)
  5534. {
  5535.     if (! block_statements)
  5536.         block_statements = (AstArray<AstStatement *> *) pool -> NewAstArray(estimate);
  5537. }
  5538.  
  5539. inline void AstSwitchBlockStatement::AddStatement(AstStatement *statement)
  5540. {
  5541.     if (! block_statements)
  5542.         AllocateBlockStatements();
  5543.     block_statements -> Next() = statement;
  5544. }
  5545.  
  5546. inline void AstSwitchBlockStatement::AllocateSwitchLabels(int estimate)
  5547. {
  5548.     if (! switch_labels)
  5549.         switch_labels = pool -> NewAstArray(estimate);
  5550. }
  5551.  
  5552. inline void AstSwitchBlockStatement::AddSwitchLabel(Ast *case_or_default_label)
  5553. {
  5554.     if (! switch_labels)
  5555.         AllocateSwitchLabels();
  5556.     switch_labels -> Next() = case_or_default_label;
  5557. }
  5558.  
  5559. inline void AstSwitchStatement::AllocateCases(int estimate)
  5560. {
  5561.     if (! cases)
  5562.         cases = pool -> NewCaseElementArray(estimate);
  5563. }
  5564.  
  5565. inline void AstSwitchStatement::AddCase(CaseElement *case_element)
  5566. {
  5567.     if (! cases)
  5568.         AllocateCases();
  5569.     cases -> Next() = case_element;
  5570. }
  5571.  
  5572. inline void AstConstructorBlock::AllocateLocalInitStatements(int estimate)
  5573. {
  5574.     if (! local_init_statements)
  5575.         local_init_statements = (AstArray<AstStatement *> *) pool -> NewAstArray(estimate);
  5576. }
  5577.  
  5578. inline void AstConstructorBlock::AddLocalInitStatement(AstStatement *statement)
  5579. {
  5580.     if (! local_init_statements)
  5581.         AllocateLocalInitStatements();
  5582.     local_init_statements -> Next() = statement;
  5583. }
  5584.  
  5585. inline void AstVariableDeclaratorId::AllocateBrackets(int estimate)
  5586. {
  5587.     if (! brackets)
  5588.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5589. }
  5590.  
  5591. inline void AstVariableDeclaratorId::AddBrackets(AstBrackets *bracket)
  5592. {
  5593.     if (! brackets)
  5594.         AllocateBrackets();
  5595.     brackets -> Next() = bracket;
  5596. }
  5597.  
  5598. inline void AstArrayType::AllocateBrackets(int estimate)
  5599. {
  5600.     if (! brackets)
  5601.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5602. }
  5603.  
  5604. inline void AstArrayType::AddBrackets(AstBrackets *bracket)
  5605. {
  5606.     if (! brackets)
  5607.         AllocateBrackets();
  5608.     brackets -> Next() = bracket;
  5609. }
  5610.  
  5611. inline void AstMethodDeclarator::AllocateBrackets(int estimate)
  5612. {
  5613.     if (! brackets)
  5614.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5615. }
  5616.  
  5617. inline void AstMethodDeclarator::AddBrackets(AstBrackets *bracket)
  5618. {
  5619.     if (! brackets)
  5620.         AllocateBrackets();
  5621.     brackets -> Next() = bracket;
  5622. }
  5623.  
  5624. inline void AstArrayCreationExpression::AllocateBrackets(int estimate)
  5625. {
  5626.     if (! brackets)
  5627.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5628. }
  5629.  
  5630. inline void AstArrayCreationExpression::AddBrackets(AstBrackets *bracket)
  5631. {
  5632.     if (! brackets)
  5633.         AllocateBrackets();
  5634.     brackets -> Next() = bracket;
  5635. }
  5636.  
  5637. inline void AstCastExpression::AllocateBrackets(int estimate)
  5638. {
  5639.     if (! brackets)
  5640.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5641. }
  5642.  
  5643. inline void AstCastExpression::AddBrackets(AstBrackets *bracket)
  5644. {
  5645.     if (! brackets)
  5646.         AllocateBrackets();
  5647.     brackets -> Next() = bracket;
  5648. }
  5649.  
  5650. inline void AstArrayCreationExpression::AllocateDimExprs(int estimate)
  5651. {
  5652.     if (! dim_exprs)
  5653.         dim_exprs = (AstArray<AstDimExpr *> *) pool -> NewAstArray(estimate);
  5654. }
  5655.  
  5656. inline void AstArrayCreationExpression::AddDimExpr(AstDimExpr *dim_expr)
  5657. {
  5658.     if (! dim_exprs)
  5659.         AllocateDimExprs(); // will not be executed as we can assume dim_exprs has already beenallocated
  5660.     dim_exprs -> Next() = dim_expr;
  5661. }
  5662.  
  5663. inline void AstThisCall::AllocateArguments(int estimate)
  5664. {
  5665.     if (! arguments)
  5666.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5667. }
  5668.  
  5669. inline void AstThisCall::AddArgument(AstExpression *argument)
  5670. {
  5671.     if (! arguments)
  5672.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5673.     arguments -> Next() = argument;
  5674. }
  5675.  
  5676. inline void AstSuperCall::AllocateArguments(int estimate)
  5677. {
  5678.     if (! arguments)
  5679.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5680. }
  5681.  
  5682. inline void AstSuperCall::AddArgument(AstExpression *argument)
  5683. {
  5684.     if (! arguments)
  5685.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5686.     arguments -> Next() = argument;
  5687. }
  5688.  
  5689. inline void AstClassInstanceCreationExpression::AllocateArguments(int estimate)
  5690. {
  5691.     if (! arguments)
  5692.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5693. }
  5694.  
  5695. inline void AstClassInstanceCreationExpression::AddArgument(AstExpression *argument)
  5696. {
  5697.     if (! arguments)
  5698.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5699.     arguments -> Next() = argument;
  5700. }
  5701.  
  5702. inline void AstMethodInvocation::AllocateArguments(int estimate)
  5703. {
  5704.     if (! arguments)
  5705.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5706. }
  5707.  
  5708. inline void AstMethodInvocation::AddArgument(AstExpression *argument)
  5709. {
  5710.     if (! arguments)
  5711.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5712.     arguments -> Next() = argument;
  5713. }
  5714.  
  5715. inline void AstThisCall::AllocateLocalArguments(int estimate)
  5716. {
  5717.     if (! local_arguments_opt)
  5718.         local_arguments_opt = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5719. }
  5720.  
  5721. inline void AstThisCall::AddLocalArgument(AstExpression *argument)
  5722. {
  5723.     if (! local_arguments_opt)
  5724.         AllocateLocalArguments();
  5725.     local_arguments_opt -> Next() = argument;
  5726. }
  5727.  
  5728. inline void AstSuperCall::AllocateLocalArguments(int estimate)
  5729. {
  5730.     if (! local_arguments_opt)
  5731.         local_arguments_opt = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5732. }
  5733.  
  5734. inline void AstSuperCall::AddLocalArgument(AstExpression *argument)
  5735. {
  5736.     if (! local_arguments_opt)
  5737.         AllocateLocalArguments();
  5738.     local_arguments_opt -> Next() = argument;
  5739. }
  5740.  
  5741. inline void AstClassInstanceCreationExpression::AllocateLocalArguments(int estimate)
  5742. {
  5743.     if (! local_arguments_opt)
  5744.         local_arguments_opt = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5745. }
  5746.  
  5747. inline void AstClassInstanceCreationExpression::AddLocalArgument(AstExpression *argument)
  5748. {
  5749.     if (! local_arguments_opt)
  5750.         AllocateLocalArguments();
  5751.     local_arguments_opt -> Next() = argument;
  5752. }
  5753.  
  5754. inline void AstMethodDeclaration::AllocateThrows(int estimate)
  5755. {
  5756.     if (! throws)
  5757.         throws = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5758. }
  5759.  
  5760. inline void AstMethodDeclaration::AddThrow(AstExpression *exception)
  5761. {
  5762.     if (! throws)
  5763.         AllocateThrows();
  5764.     throws -> Next() = exception;
  5765. }
  5766.  
  5767. inline void AstConstructorDeclaration::AllocateThrows(int estimate)
  5768. {
  5769.     if (! throws)
  5770.         throws = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5771. }
  5772.  
  5773. inline void AstConstructorDeclaration::AddThrow(AstExpression *exception)
  5774. {
  5775.     if (! throws)
  5776.         AllocateThrows();
  5777.     throws -> Next() = exception;
  5778. }
  5779.  
  5780. inline void AstMethodDeclarator::AllocateFormalParameters(int estimate)
  5781. {
  5782.     if (! formal_parameters)
  5783.         formal_parameters = (AstArray<AstFormalParameter *> *) pool -> NewAstArray(estimate);
  5784. }
  5785.  
  5786. inline void AstMethodDeclarator::AddFormalParameter(AstFormalParameter *formal_parameter)
  5787. {
  5788.     if (! formal_parameters)
  5789.         AllocateFormalParameters();
  5790.     formal_parameters -> Next() = formal_parameter;
  5791. }
  5792.  
  5793. inline void AstLocalVariableDeclarationStatement::AllocateVariableDeclarators(int estimate)
  5794. {
  5795.     if (! variable_declarators)
  5796.         variable_declarators = (AstArray<AstVariableDeclarator *> *) pool -> NewAstArray(estimate);
  5797. }
  5798.  
  5799. inline void AstLocalVariableDeclarationStatement::AddVariableDeclarator(AstVariableDeclarator *variable_declarator)
  5800. {
  5801.     if (! variable_declarators)
  5802.         AllocateVariableDeclarators();
  5803.     variable_declarators -> Next() = variable_declarator;
  5804. }
  5805.  
  5806. inline void AstFieldDeclaration::AllocateVariableDeclarators(int estimate)
  5807. {
  5808.     if (! variable_declarators)
  5809.         variable_declarators = (AstArray<AstVariableDeclarator *> *) pool -> NewAstArray(estimate);
  5810. }
  5811.  
  5812. inline void AstFieldDeclaration::AddVariableDeclarator(AstVariableDeclarator *variable_declarator)
  5813. {
  5814.     if (! variable_declarators)
  5815.         AllocateVariableDeclarators();
  5816.     variable_declarators -> Next() = variable_declarator;
  5817. }
  5818.  
  5819. inline void AstClassDeclaration::AllocateInterfaces(int estimate)
  5820. {
  5821.     if (! interfaces)
  5822.         interfaces = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5823. }
  5824.  
  5825. inline void AstClassDeclaration::AddInterface(AstExpression *interf)
  5826. {
  5827.     if (! interfaces)
  5828.         AllocateInterfaces();
  5829.     interfaces -> Next() = interf;
  5830. }
  5831.  
  5832. inline void AstInterfaceDeclaration::AllocateExtendsInterfaces(int estimate)
  5833. {
  5834.     if (! extends_interfaces)
  5835.         extends_interfaces = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5836. }
  5837.  
  5838. inline void AstInterfaceDeclaration::AddExtendsInterface(AstExpression *interf)
  5839. {
  5840.     if (! extends_interfaces)
  5841.         AllocateExtendsInterfaces();
  5842.     extends_interfaces -> Next() = interf;
  5843. }
  5844.  
  5845. inline void AstInterfaceDeclaration::AllocateInterfaceMemberDeclarations(int estimate)
  5846. {
  5847.     if (! interface_member_declarations)
  5848.         interface_member_declarations = pool -> NewAstArray(estimate);
  5849. }
  5850.  
  5851. inline void AstInterfaceDeclaration::AddInterfaceMemberDeclaration(Ast *member)
  5852. {
  5853.     if (! interface_member_declarations)
  5854.         AllocateInterfaceMemberDeclarations();
  5855.     interface_member_declarations -> Next() = member;
  5856. }
  5857.  
  5858. inline void AstClassBody::AllocateClassBodyDeclarations(int estimate)
  5859. {
  5860.     if (! class_body_declarations)
  5861.         class_body_declarations = pool -> NewAstArray(estimate);
  5862. }
  5863.  
  5864. inline void AstClassBody::AddClassBodyDeclaration(Ast *member)
  5865. {
  5866.     if (! class_body_declarations)
  5867.         AllocateClassBodyDeclarations();
  5868.     class_body_declarations -> Next() = member;
  5869. }
  5870.  
  5871. // not inline
  5872. void AstClassBody::AddClassBodyDeclarationNicely(Ast *member)
  5873. {
  5874.     AstFieldDeclaration *field_declaration = member -> FieldDeclarationCast();
  5875.     AstMethodDeclaration *method_declaration = member -> MethodDeclarationCast();
  5876.     AstConstructorDeclaration *constructor_declaration = member -> ConstructorDeclarationCast();
  5877.     AstStaticInitializer *static_initializer = member -> StaticInitializerCast();
  5878.     AstClassDeclaration *class_declaration = member -> ClassDeclarationCast();
  5879.     AstInterfaceDeclaration *interface_declaration = member -> InterfaceDeclarationCast();
  5880.     AstBlock *block = member -> BlockCast();
  5881.  
  5882.     AddClassBodyDeclaration(member);
  5883.  
  5884.  
  5885.     // This is lifted from Parser::Act68.
  5886.  
  5887.     if (field_declaration)
  5888.     {
  5889.         if (field_declaration -> StaticFieldCast())
  5890.             AddClassVariable(field_declaration);
  5891.         else AddInstanceVariable(field_declaration);
  5892.     }
  5893.     else if (method_declaration)
  5894.     {
  5895.         AddMethod(method_declaration);
  5896.     }
  5897.     else if (constructor_declaration)
  5898.     {
  5899.         AddConstructor(constructor_declaration);
  5900.     }
  5901.     else if (static_initializer)
  5902.     {
  5903.         AddStaticInitializer(static_initializer);
  5904.     }
  5905.     else if (class_declaration)
  5906.     {
  5907.         AddNestedClass(class_declaration);
  5908.     }
  5909.     else if (interface_declaration)
  5910.     {
  5911.         AddNestedInterface(interface_declaration);
  5912.     }
  5913.     else if (block)
  5914.     {
  5915.         AddBlock(block);
  5916.     }
  5917.     else // assert(block = member -> EmptyDeclarationCast())
  5918.     {
  5919.         AddEmptyDeclaration((AstEmptyDeclaration *) member);
  5920.     }
  5921. }
  5922.  
  5923. inline void AstForStatement::AllocateForInitStatements(int estimate)
  5924. {
  5925.     if (! for_init_statements)
  5926.         for_init_statements = (AstArray<AstStatement *> *) pool -> NewAstArray(estimate);
  5927. }
  5928.  
  5929. inline void AstForStatement::AddForInitStatement(AstStatement *statement)
  5930. {
  5931.     if (! for_init_statements)
  5932.         AllocateForInitStatements();
  5933.     for_init_statements -> Next() = statement;
  5934. }
  5935.  
  5936. inline void AstForStatement::AllocateForUpdateStatements(int estimate)
  5937. {
  5938.     if (! for_update_statements)
  5939.         for_update_statements = (AstArray<AstExpressionStatement *> *) pool -> NewAstArray(estimate);
  5940. }
  5941.  
  5942. inline void AstForStatement::AddForUpdateStatement(AstExpressionStatement *statement)
  5943. {
  5944.     if (! for_update_statements)
  5945.         AllocateForUpdateStatements();
  5946.     for_update_statements -> Next() = statement;
  5947. }
  5948.  
  5949. inline void AstArrayInitializer::AllocateVariableInitializers(int estimate)
  5950. {
  5951.     if (! variable_initializers)
  5952.         variable_initializers = pool -> NewAstArray(estimate);
  5953. }
  5954.  
  5955. inline void AstArrayInitializer::AddVariableInitializer(Ast *initializer)
  5956. {
  5957.     if (! variable_initializers)
  5958.         AllocateVariableInitializers();
  5959.     variable_initializers -> Next() = initializer;
  5960. }
  5961.  
  5962. inline void AstTryStatement::AllocateCatchClauses(int estimate)
  5963. {
  5964.     if (! catch_clauses)
  5965.         catch_clauses = (AstArray<AstCatchClause *> *) pool -> NewAstArray(estimate);
  5966. }
  5967.  
  5968. inline void AstTryStatement::AddCatchClause(AstCatchClause *catch_clause)
  5969. {
  5970.     if (! catch_clauses)
  5971.         AllocateCatchClauses();
  5972.     catch_clauses -> Next() = catch_clause;
  5973. }
  5974.  
  5975. inline void AstCompilationUnit::AllocateImportDeclarations(int estimate)
  5976. {
  5977.     if (! import_declarations)
  5978.         import_declarations = (AstArray<AstImportDeclaration *> *) pool -> NewAstArray(estimate);
  5979. }
  5980.  
  5981. inline void AstCompilationUnit::AddImportDeclaration(AstImportDeclaration *import_declaration)
  5982. {
  5983.     if (! import_declarations)
  5984.         AllocateImportDeclarations();
  5985.     import_declarations -> Next() = import_declaration;
  5986. }
  5987.  
  5988. inline void AstCompilationUnit::AllocateTypeDeclarations(int estimate)
  5989. {
  5990.     if (! type_declarations)
  5991.         type_declarations = pool -> NewAstArray(estimate);
  5992. }
  5993.  
  5994. inline void AstCompilationUnit::AddTypeDeclaration(Ast *type_declaration)
  5995. {
  5996.     if (! type_declarations)
  5997.         AllocateTypeDeclarations();
  5998.     type_declarations -> Next() = type_declaration;
  5999. }
  6000.  
  6001.  
  6002. //
  6003. // Allocate another block of storage for the ast array.
  6004. //
  6005. template <class T>
  6006.     void AstArray<T>::AllocateMoreSpace()
  6007.     {
  6008.         //
  6009.         //
  6010.         // The variable size always indicates the maximum number of
  6011.         // elements that has been allocated for the array.
  6012.         // Initially, it is set to 0 to indicate that the array is empty.
  6013.         // The pool of available elements is divided into segments of size
  6014.         // 2**log_blksize each. Each segment is pointed to by a slot in
  6015.         // the array base.
  6016.         //
  6017.         // By dividing size by the size of the segment we obtain the
  6018.         // index for the next segment in base. If base is full, it is
  6019.         // reallocated.
  6020.         //
  6021.         //
  6022.         size_t k = size >> log_blksize; /* which segment? */
  6023.  
  6024.         //
  6025.         // If the base is overflowed, reallocate it and initialize the new elements to NULL.
  6026.         //
  6027.         if (k == base_size)
  6028.         {
  6029.             int old_base_size = base_size;
  6030.             T **old_base = base;
  6031.  
  6032.             base_size += base_increment;
  6033.  
  6034.             assert(base_size <= pool -> Blksize()); // There must be enough room to allocate base
  6035.  
  6036.             base = (T **) pool -> Alloc(sizeof(T *) * base_size);
  6037.  
  6038.             if (old_base != NULL)
  6039.             {
  6040.                 memmove(base, old_base, old_base_size * sizeof(T *));
  6041. // STG:
  6042. //                delete [] old_base;
  6043.             }
  6044.             memset(&base[old_base_size], 0, (base_size - old_base_size) * sizeof(T *));
  6045.         }
  6046.  
  6047.         //
  6048.         // We allocate a new segment and place its adjusted address in
  6049.         // base[k]. The adjustment allows us to index the segment directly,
  6050.         // instead of having to perform a subtraction for each reference.
  6051.         // See operator[] below.
  6052.         //
  6053.         assert(Blksize() <= pool -> Blksize()); // There must be enough room to allocate block
  6054.  
  6055.         base[k] = (T *) pool -> Alloc(sizeof(T) * Blksize());
  6056.         base[k] -= size;
  6057.  
  6058.         //
  6059.         // Finally, we update size.
  6060.         //
  6061.         size += Blksize();
  6062.  
  6063.         return;
  6064.     }
  6065.  
  6066.  
  6067. template <class T>
  6068.     //
  6069.     // Constructor of a ast array.
  6070.     //
  6071.     AstArray<T>::AstArray(StoragePool *pool_, unsigned estimate) : pool(pool_)
  6072.     {
  6073.         assert(sizeof(T) == sizeof(StoragePool::Cell)); // AstArray should only be used for arrays of pointers.
  6074.         assert(pool -> Blksize() >= 256); // There must be enough space in the storage pool to move !!!
  6075.  
  6076.         if (estimate == 0)
  6077.             log_blksize = 6; // take a guess
  6078.         else
  6079.         {
  6080.             for (log_blksize = 1; (((unsigned) 1 << log_blksize) < estimate) && (log_blksize < 31); log_blksize++)
  6081.                 ;
  6082.         }
  6083.  
  6084.         //
  6085.         // Increment a base_increment size that is big enough not to have to
  6086.         // be reallocated. Find a block size that is smaller that the block
  6087.         // size of the pool.
  6088.         //
  6089.         base_increment = (Blksize() > pool -> Blksize() ? Blksize() / pool -> Blksize() : 1) * 2;
  6090.         while (Blksize() >= pool -> Blksize())
  6091.             log_blksize--;
  6092.  
  6093.         base_size = 0;
  6094.         size = 0;
  6095.         top = 0;
  6096.         base = NULL;
  6097.     }
  6098.  
  6099.  
  6100. #endif
  6101.